Skip to contents

[Stable] This is often useful for choices_selected as it marks up the drop-down boxes for shiny::selectInput().

[Stable]

Usage

choices_labeled(choices, labels, subset = NULL, types = NULL)

# S3 method for choices_labeled
print(x, ...)

Arguments

choices

A character / factor / numeric / logical vector.

labels

character vector containing labels to be applied to choices. If NA then "Label Missing" will be used.

subset

a vector that is a subset of choices. This is useful if only a few variables need to be named. If this argument is used, the returned vector will match its order.

types

Character vector containing the types of the columns to be used for applying the appropriate icons to the choices_selected drop down box. (e.g. "numeric")

x

an object used to select a method.

...

further arguments passed to or from other methods.

Value

a named character vector

Details

If either choices or labels are factors, they are coerced to character. Duplicated elements from choices get removed.

Examples

library(shiny)

ADSL <- teal.transform::rADSL
ADTTE <- teal.transform::rADTTE
choices1 <- choices_labeled(names(ADSL), teal.data::col_labels(ADSL, fill = FALSE))
choices2 <- choices_labeled(ADTTE$PARAMCD, ADTTE$PARAM)
# if only a subset of variables are needed, use subset argument
choices3 <- choices_labeled(
  names(ADSL),
  teal.data::col_labels(ADSL, fill = FALSE),
  subset = c("ARMCD", "ARM")
)
if (FALSE) {
shinyApp(
  ui = fluidPage(
    selectInput("c1",
      label = "Choices from ADSL",
      choices = choices1,
      selected = choices1[1]
    ),
    selectInput("c2",
      label = "Choices from ADTTE",
      choices = choices2,
      selected = choices2[1]
    ),
    selectInput("c3",
      label = "Arm choices from ADSL",
      choices = choices3,
      selected = choices3[1]
    )
  ),
  server = function(input, output) {}
)
}