sa_buttongroup: Button group input

Description Usage Arguments Details Value Examples

View source: R/buttongroup.R

Description

A Shiny button group input.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
sa_buttongroup(
  inputId,
  label,
  choices = NULL,
  selected = NULL,
  multiple = FALSE,
  color = "#555555",
  width = NULL,
  choiceNames = NULL,
  choiceValues = NULL
)

update_sa_buttongroup(
  session,
  inputId,
  label = NULL,
  choices = NULL,
  selected = NULL
)

Arguments

inputId

The id of the input object.

label

The label to set for the input object.

choices

List of values to show buttons for. If elements of the list are named then that name rather than the value is displayed to the user. If this argument is provided, then choiceNames and choiceValues must not be provided, and vice-versa. The values should be strings; other types (such as logicals and numbers) will be coerced to strings.

selected

The radio value that should be initially selected; or checkbox group values, if any.

multiple

logical, allow multiple selections.

color

character, hex or R color name.

width

not in use

choiceNames, choiceValues

See shiny::checkboxgroup. Vector of names and values, must have same length.

session

The session object passed to function given to shinyServer.

Details

The button group is a wrapper around sa_radio when multiple = FALSE and sa_checkboxgroup when multiple = TRUE.

Value

A list of HTML elements that can be added to a UI definition.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
if (interactive()) {
library(shiny)

ui <- function(request) {
fluidPage(
  use_access(),
  fluidRow(bookmarkButton()),
  fluidRow(
    column(3,
      actionButton("btn1", "Reset single button group to first"),
      sa_buttongroup(
        "bg1", "Single variable to show:",
        c("Cylinders" = "cyl", "Transmission" = "am", "Gears" = "gear", "A" = "a", "B" = "b"),
        selected = "am", color = "dodgerblue"),
      tableOutput("data1")
    ),
    column(3,
    actionButton("btn2", "Reset multiple button group to none"),
      sa_buttongroup(
        "bg2", "Multiple variables to show:",
        selected = c("cyl", "am"), multiple = TRUE, color = "firebrick",
        choiceNames = c("Cylinders", "Transmission", "Gears"),
        choiceValues = c("cyl", "am", "gear")),
      tableOutput("data2")
    )
  )
)
}

server <- function(input, output, session) {
  output$data1 <- renderTable({
    mtcars[, c("mpg", input$bg1), drop = FALSE]
  }, rownames = TRUE)

  output$data2 <- renderTable({
    mtcars[, c("mpg", input$bg2), drop = FALSE]
  }, rownames = TRUE)

  observeEvent(input$btn1, {
    update_sa_buttongroup(session, "bg1", selected = "cyl")
  })
  observeEvent(input$btn2, {
    update_sa_buttongroup(session, "bg2", selected = character(0))
  })
}

shinyApp(ui, server, enableBookmarking = "url")

}

leonawicz/shinyaccess documentation built on Aug. 15, 2020, 12:40 a.m.