R Language Checkbox Group


Example

Create a group of checkboxes that can be used to toggle multiple choices independently. The server will receive the input as a character vector of the selected values.

library(shiny)

ui <- fluidPage(    
  checkboxGroupInput("checkGroup1", label = h3("This is a Checkbox group"), 
                 choices = list("1" = 1, "2" = 2, "3" = 3),
                 selected = 1),
  fluidRow(column(3, verbatimTextOutput("text_choice")))
  ) 


server <- function(input, output){
  output$text_choice <- renderPrint({
    return(paste0("You have chosen the choice ",input$checkGroup1))})
} 

shinyApp(ui = ui, server = server)

enter image description here

It's possible to change the settings :

  • label : title
  • choices : selected values
  • selected : The initially selected value (NULL for no selection)
  • inline : horizontal or vertical
  • width

It is also possible to add HTML.