validate_n_levels | R Documentation |
validate_n_levels(x, min_levels = 1, max_levels = 12, var_name)
x |
variable name. If |
min_levels |
cutoff for minimum number of levels of |
max_levels |
cutoff for maximum number of levels of |
var_name |
name of variable being validated for use in validation message |
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
.
data <- data.frame(
one = rep("a", length.out = 20),
two = rep(c("a", "b"), length.out = 20),
three = rep(c("a", "b", "c"), length.out = 20),
four = rep(c("a", "b", "c", "d"), length.out = 20),
stringsAsFactors = TRUE
)
ui <- fluidPage(
selectInput(
"var",
"Select variable",
choices = c("one", "two", "three", "four"),
selected = "one"
),
verbatimTextOutput("summary")
)
server <- function(input, output) {
output$summary <- renderText({
validate_n_levels(data[[input$var]], min_levels = 2, max_levels = 15, var_name = input$var)
paste0(
"Levels of selected treatment variable: ",
paste(levels(data[[input$var]]),
collapse = ", "
)
)
})
}
if (interactive()) {
shinyApp(ui, server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.