Checkbox

#| standalone: true
#| components: [viewer]
#| viewerHeight: 150

library(shiny)
library(bslib)

ui <- page_fixed(
  checkboxInput("checkbox", "Checkbox", FALSE),
  verbatimTextOutput("value")
)

server <- function(input, output) {
  output$value <- renderText({ input$checkbox })
}

shinyApp(ui, server)
library(shiny)
library(bslib)

ui <- page_fixed(
  checkboxInput("checkbox", "Checkbox", FALSE), 
  verbatimTextOutput("value")
)

server <- function(input, output) {
  output$value <- renderText({ input$checkbox })
}

shinyApp(ui, server)
No matching items

Relevant Functions

  • checkboxInput()
    checkboxInput(inputId, label, value = FALSE, width = NULL)

No matching items

Details

A checkbox creates a single checkbox that can be used to specify logical values.

Follow these steps to add a checkbox to your app:

  1. Add checkboxInput() to the UI of your app to create a checkbox. Where you call this function will determine where the checkbox will appear within the app’s layout.

  2. Supply values to checkboxInput()’s first two arguments (inputId and label) to specify the id and label of the checkbox. Optionally, set the value argument to either TRUE or FALSE to specify the initial value of the checkbox. By default, the checkbox has value FALSE and is un-checked.

The value of an input component is accessible as a reactive value within the server() function. To access the value of a checkbox:

  1. Use input$<checkbox_id> (e.g., input$checkbox) to access the value of a checkbox. The server value of a checkbox is TRUE if checked and FALSE if not checked.

See also: Checkbox Group