Checkbox Group
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
library(shiny)
library(bslib)
ui <- page_fixed(
checkboxGroupInput(
"checkbox_group",
"Checkbox group",
c(
"A" = "a",
"B" = "b",
"C" = "c"
)
),
verbatimTextOutput("value")
)
server <- function(input, output) {
output$value <- renderText({ input$checkbox_group })
}
shinyApp(ui, server)
library(shiny)
library(bslib)
ui <- page_fixed(
checkboxGroupInput(
"checkbox_group",
"Checkbox group",
c(
"A" = "a",
"B" = "b",
"C" = "c"
)
),
verbatimTextOutput("value")
)
server <- function(input, output) {
output$value <- renderText({ input$checkbox_group })
}
shinyApp(ui, server)
Relevant Functions
-
checkboxGroupInput
checkboxGroupInput(inputId, label, choices = NULL, selected = NULL, inline = FALSE, width = NULL, choiceNames = NULL, choiceValues = NULL)
Details
A checkbox group creates a group of checkboxes that can be used to toggle multiple choices independently.
Follow these steps to display a checkbox group in your app:
Add
checkboxGroupInput()
to the UI of your app to create a checkbox group. Where you call this function will determine where the checkbox group will appear within the app’s layout.Specify the
inputId
andlabel
arguments ofcheckboxGroupInput()
to define the identifier and label of the checkbox group.Supply the
choices
argument with a list of choices. If the elements of the list are named, the names will be displayed to the user, instead of the values. Optionally, supply values to theselected
argument to control the initially selected items.
The value of an input component is accessible as a reactive value within the server()
function. To access the value of a checkbox group:
- Use
input$<checkbox_group_id>
(e.g.,input$checkbox_group
) to access the value of a checkbox group. The server value of a checkbox group is a character vector of values corresponding to the boxes that are checked.
See also: Checkbox