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)
No matching items

Relevant Functions

  • checkboxGroupInput
    checkboxGroupInput(inputId, label, choices = NULL, selected = NULL, inline = FALSE, width = NULL, choiceNames = NULL, choiceValues = NULL)

No matching items

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:

  1. 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.

  2. Specify the inputId and label arguments of checkboxGroupInput() to define the identifier and label of the checkbox group.

  3. 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 the selected 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:

  1. 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