validate_in: Validates that vector includes all expected values

View source: R/validations.R

validate_inR Documentation

Validates that vector includes all expected values

Description

[Stable]

Usage

validate_in(x, choices, msg)

Arguments

x

Vector of values to test.

choices

Vector to test against.

msg

(character(1)) Error message to display if some elements of x are not elements of choices.

Details

This function is a wrapper for shiny::validate.

Examples

ui <- fluidPage(
  selectInput(
    "species",
    "Select species",
    choices = c("setosa", "versicolor", "virginica", "unknown species"),
    selected = "setosa",
    multiple = FALSE
  ),
  verbatimTextOutput("summary")
)

server <- function(input, output) {
  output$summary <- renderPrint({
    validate_in(input$species, iris$Species, "Species does not exist.")
    nrow(iris[iris$Species == input$species, ])
  })
}
if (interactive()) {
  shinyApp(ui, server)
}


teal documentation built on May 29, 2024, 10:11 a.m.