Description Usage Arguments Value Examples
View source: R/checkboxgroup.R
A Shiny checkbox group input.
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
)
|
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 |
selected |
The values that should be initially selected, if any. |
color |
character, hex or R color name. |
ncol |
number of columns when |
inline |
if |
width |
not in use |
choiceNames, choiceValues |
See |
session |
The session object passed to function given to shinyServer. |
A list of HTML elements that can be added to a UI definition.
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")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.