Skip to contents

[Stable] Hidden input widgets are useful to have the input[[inputId]] variable on available in the server function but no corresponding visual clutter from input widgets that provide only a single choice.

Usage

optionalSelectInput(
  inputId,
  label = NULL,
  choices = NULL,
  selected = NULL,
  multiple = FALSE,
  sep = NULL,
  options = list(),
  label_help = NULL,
  fixed = FALSE,
  width = NULL
)

Arguments

inputId

The input slot that will be used to access the value.

label

Display label for the control, or NULL for no label.

choices

(character, NULL)
If choices is NULL no pickerInput widget is displayed and input[[inputId]] will be "". If choices is of length 1 then a label and character string will be displayed and the pickerInput widget will be hidden. If the length of choices is more than one the pickerInput element will be displayed. If elements of the list are named then that name rather than the value is displayed to the user.

selected

The initially selected value (or multiple values if multiple = TRUE). If not specified then defaults to the first value for single-select lists and no values for multiple select lists.

multiple

Is selection of multiple items allowed?

sep

(character(1))
A separator string to split the choices or selected inputs into the values of the different columns.

options

List of options, see pickerOptions for all available options. To limit the number of selection possible, see example below.

label_help

(shiny.tag optional)
e.g. an object returned by shiny::helpText().

fixed

(logical(1) optional)
whether to block user to select choices.

width

(character(1))
The width of the input passed to pickerInput e.g. 'auto', 'fit', '100px' or '75%'

Examples

if (FALSE) {
optionalSelectInput(inputId = "xvar", label = "x variable", choices = "A", selected = "A")
optionalSelectInput(
  inputId = "xvar",
  label = "x variable",
  choices = LETTERS[1:5],
  selected = "A"
)
optionalSelectInput(
  inputId = "xvar",
  label = "x variable",
  choices = c("A - value A" = "A"),
  selected = "A"
)


# Create a minimal example data frame
data <- data.frame(
  AGE = c(25, 30, 40, 35, 28),
  SEX = c("Male", "Female", "Male", "Female", "Male"),
  PARAMCD = c("Val1", "Val2", "Val3", "Val4", "Val5"),
  PARAM = c("Param1", "Param2", "Param3", "Param4", "Param5"),
  AVISIT = c("Visit1", "Visit2", "Visit3", "Visit4", "Visit5"),
  stringsAsFactors = TRUE
)
optionalSelectInput(
  inputId = "xvar",
  label = "x variable",
  choices = teal.transform::variable_choices(data = data, subset = c("AGE", "SEX", "PARAMCD")),
  selected = "PARAMCD"
)

selected_value <- paste0(lapply(data[1, c("PARAMCD", "AVISIT")], as.character), collapse = " - ")
optionalSelectInput(
  inputId = "xvar",
  label = "x variable",
  choices = teal.transform::value_choices(
    data = data,
    var_choices = c("PARAMCD", "AVISIT"),
    var_label = c("PARAM", "AVISIT")
  ),
  selected = selected_value
)
}