sa_checkboxgroup: Checkbox group input

Description Usage Arguments Value Examples

View source: R/checkboxgroup.R

Description

A Shiny checkbox group input.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
sa_checkboxgroup(
  inputId,
  label,
  choices = NULL,
  selected = NULL,
  color = "#555555",
  ncol = 1,
  inline = FALSE,
  width = NULL,
  choiceNames = NULL,
  choiceValues = NULL
)

update_sa_checkboxgroup(
  session,
  inputId,
  label = NULL,
  choices = NULL,
  selected = NULL,
  ncol = 1,
  inline = FALSE,
  choiceNames = NULL,
  choiceValues = NULL
)

Arguments

inputId

The id of the input object.

label

The label to set for the input object.

choices

List of values to show checkboxes 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 values that should be initially selected, if any.

color

character, hex or R color name.

ncol

number of columns when inline = FALSE. Will auto-truncate to the number of choices if exceeded.

inline

if TRUE, ncol is ignored.

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.

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
if (interactive()) {
library(shiny)

ui <- function(request) {
fluidPage(
  use_access(),
  fluidRow(bookmarkButton()),
  fluidRow(
    column(3,
      actionButton("btn1", "Reset checkbox group 1"),
      checkboxGroupInput(
        "cb1", "Shiny1 - Variables to show:",
        list("Cylinders" = "cyl", "Transmission" = "am", "Gears" = "gear"),
        width = "1000px"),
      tableOutput("data1")
    ),
    column(3,
      checkboxGroupInput(
        "cb2", "Shiny2 - Variables to show:",
        list("Cylinders" = "cyl", "Transmission" = "am", "Gears" = "gear"),
        inline = TRUE),
      tableOutput("data2")
    ),
    column(3,
      actionButton("btn3", "Reset checkbox group 3"),
      sa_checkboxgroup(
        "cb3", "SA1 - Variables to show:",
        c("Cylinders" = "cyl", "Transmission" = "am", "Gears" = "gear", "A" = "a", "B" = "b"),
        selected = c("cyl", "am"), color = "dodgerblue", ncol = 3),
      tableOutput("data3")
    ),
    column(3,
    actionButton("btn4", "Update everything (see source code for details)"),
      sa_checkboxgroup(
        "cb4", "SA2 - Variables to show:",
        selected = c("cyl", "am"), color = "firebrick",
        choiceNames = c("Cylinders", "Transmission", "Gears"),
        choiceValues = c("cyl", "am", "gear"), inline = TRUE),
      tableOutput("data4")
    )
  )
)
}

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

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

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

  observeEvent(input$btn1, {
    updateCheckboxgroup(session, "cb1", selected = character(0))
  })
  observeEvent(input$btn3, {
    update_sa_checkboxgroup(session, "cb3",
      label = "New title!", selected = c("cyl", "a")
    )
  })
  observeEvent(input$btn4, {
    update_sa_checkboxgroup(session, "cb4",
      label = "New title!",
      choices = c("am", "gear", "hello world"),
      ncol = 2,
      selected = c("am", "gear")
    )
  })
}

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

}

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