checkboxInput: Checkbox and switch inputs

View source: R/input-checkbox.R

checkboxInputR Documentation

Checkbox and switch inputs

Description

Reactive checkbox and checkbar inputs. Users may select one or more choices. The checkbox input appears as a standard checkbox or set of checkboxes. When a checkbox input has no selected choices the reactive value is NULL. Switch inputs differ from checkboxes only in appearance.

Usage

checkboxInput(
  ...,
  id,
  choices = NULL,
  values = choices,
  selected = NULL,
  inline = FALSE
)

updateCheckboxInput(
  id,
  choices = NULL,
  values = choices,
  selected = NULL,
  inline = FALSE,
  enable = NULL,
  disable = NULL,
  valid = NULL,
  invalid = NULL,
  session = getDefaultReactiveDomain()
)

switchInput(..., id, choices, values = choices, selected = NULL)

updateSwitchInput(
  id,
  choices = NULL,
  values = choices,
  selected = NULL,
  enable = NULL,
  disable = NULL,
  valid = NULL,
  invalid = NULL,
  session = getDefaultReactiveDomain()
)

Arguments

...

Additional named arguments passed as HTML attributes to the parent element or tag elements passed as child elements to the parent element.

id

A character string specifying the id of the reactive input.

choices

A character string or vector specifying a label or labels for the checkbox or checkbar.

values

A character string or vector specifying values for the checkbox or checkbar input, defaults to choice or values, respectively.

selected

One or more of values specifying which choices are selected by default, defaults to NULL, in which case no choices are initially selected.

inline

One of TRUE or FALSE specifying if the checkbox input choices render inline or stacked, defaults to FALSE, in which case the choices are stacked.

enable

One of values specifying particular choices to enable or TRUE specifying the entire input is enabled, defaults to NULL.

disable

One of values specifying particular choices to disable or TRUE specifying the entire input is disabled, defaults to NULL.

valid

A character string specifying a message to the user indicating how the input's value is valid, defaults to NULL.

invalid

A character string specifying a message to the user indicating how the input's value is invalid, defaults to NULL.

session

A reactive context, defaults to getDefaultReactiveDomain().

Details

Getting started

Checkbox inputs may have a single possible value.

checkboxInput(
  id = NULL,
  choices = "Choice 1",
  selected = "Choice 1"
)

You may also specify multiple possible values.

checkboxInput(
  id = NULL,
  choices = c("Choice 1", "Choice 2", "Choice 3"),
  selected = c("Choice 1", "Choice 2")
)

Layout

While checkbox input choices are typically laid out vertically you can lay out the choices horizontally with inline = TRUE.

checkboxInput(
  id = NULL,
  choices = c("Choice 1", "Choice 2", "Choice 3"),
  inline = TRUE  # <-
)

Switch variant

The switch input functions identical to the checkbox input with a different appearance.

switchInput(
  id = NULL,
  choices = c("Toggle 1", "Toggle 2", "Toggle 3"),
  selected = "Toggle 2"
)

Background color

Changing the background color of a checkbox or switch input will modify the background color of the selected choices.

checkboxInput(
  .style %>%
    background("warning"),
  id = NULL,
  choices = c("Choice 1", "Choice 2"),
  selected = c("Choice 1", "Choice 2")
)
switchInput(
  .style %>%
    background("success"),
  id = NULL,
  choices = c("Toggle 1", "Toggle 2"),
  selected = "Toggle 1"
)

Labelling

formGroup(
  label = "Label",
  checkboxInput(
    id = NULL,
    choices = c("Choice 1", "Choice 2")
  ),
  help = "Help text for the input"
)
Help text for the input

See Also

Other inputs: buttonGroupInput(), buttonInput(), checkbarInput(), chipInput(), fileInput(), formInput(), listGroupInput(), menuInput(), navInput(), radioInput(), radiobarInput(), rangeInput(), selectInput(), textInput()


nteetor/dull documentation built on June 10, 2022, 11:30 a.m.