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)
Relevant Functions
-
checkboxInput()
checkboxInput(inputId, label, value = FALSE, width = NULL)
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:
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.Supply values to
checkboxInput()
’s first two arguments (inputId
andlabel
) to specify the id and label of the checkbox. Optionally, set thevalue
argument to eitherTRUE
orFALSE
to specify the initial value of the checkbox. By default, the checkbox has valueFALSE
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:
- Use
input$<checkbox_id>
(e.g.,input$checkbox
) to access the value of a checkbox. The server value of a checkbox isTRUE
if checked andFALSE
if not checked.
See also: Checkbox Group