Description Usage Arguments Details Value Examples
A Shiny button group input.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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 |
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 |
session |
The session object passed to function given to shinyServer. |
The button group is a wrapper around sa_radio
when
multiple = FALSE
and sa_checkboxgroup
when
multiple = TRUE
.
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 | 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")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.