| 1 |
#' Checkbox Input Control |
| 2 |
#' |
| 3 |
#' Create a checkbox that can be used to specify logical values. |
| 4 |
#' |
| 5 |
#' @inheritParams textInput |
| 6 |
#' @param value Initial value (`TRUE` or `FALSE`). |
| 7 |
#' @return A checkbox control that can be added to a UI definition. |
| 8 |
#' |
| 9 |
#' @family input elements |
| 10 |
#' @seealso [checkboxGroupInput()], [updateCheckboxInput()] |
| 11 |
#' |
| 12 |
#' @examples |
| 13 |
#' ## Only run examples in interactive R sessions |
| 14 |
#' if (interactive()) { |
| 15 |
#' |
| 16 |
#' ui <- fluidPage( |
| 17 |
#' checkboxInput("somevalue", "Some value", FALSE), |
| 18 |
#' verbatimTextOutput("value") |
| 19 |
#' ) |
| 20 |
#' server <- function(input, output) { |
| 21 |
#' output$value <- renderText({ input$somevalue }) |
| 22 |
#' } |
| 23 |
#' shinyApp(ui, server) |
| 24 |
#' } |
| 25 |
#' |
| 26 |
#' @section Server value: |
| 27 |
#' `TRUE` if checked, `FALSE` otherwise. |
| 28 |
#' |
| 29 |
#' @export |
| 30 |
checkboxInput <- function(inputId, label, value = FALSE, width = NULL) { |
| 31 |
|
| 32 |
value <- restoreInput(id = inputId, default = value) |
| 33 |
|
| 34 |
inputTag <- tags$input(id = inputId, type="checkbox", class = "shiny-input-checkbox") |
| 35 |
if (!is.null(value) && value) |
| 36 |
inputTag$attribs$checked <- "checked" |
| 37 |
|
| 38 |
div(class = "form-group shiny-input-container", |
| 39 |
style = css(width = validateCssUnit(width)), |
| 40 |
div(class = "checkbox", |
| 41 |
tags$label(inputTag, tags$span(label)) |
| 42 |
) |
| 43 |
) |
| 44 |
} |