Skip to contents

[Stable]

Usage

validate_n_levels(x, min_levels = 1, max_levels = 12, var_name)

Arguments

x

variable name. If x is not a factor, the unique values are treated as levels.

min_levels

cutoff for minimum number of levels of x

max_levels

cutoff for maximum number of levels of x

var_name

name of variable being validated for use in validation message

Details

If the number of levels of x is less than min_levels or greater than max_levels the validation will fail. This function is a wrapper for shiny::validate.

Examples

library(scda)

ADSL <- synthetic_cdisc_data("latest")$adsl

ui <- fluidPage(
  selectInput("arm", "Select treatment",
    choices = c("ARM", "ARMCD", "STUDYID"), selected = "ARM"
  ),
  verbatimTextOutput("arm_summary")
)

server <- function(input, output) {
  output$arm_summary <- renderText({
    validate_n_levels(ADSL[[input$arm]],
      min_levels = 2, max_levels = 15,
      var_name = input$arm
    )
    paste0(
      "Levels of selected treatment variable: ",
      paste(levels(ADSL[[input$arm]]),
        collapse = ", "
      )
    )
  })
}
if (FALSE) {
shinyApp(ui, server)
}