Validate input values and other conditions

For an output rendering function (e.g. renderPlot()), you may need to check that certain input values are available and valid before you can render the output. validate gives you a convenient mechanism for doing so.

validate(..., errorClass = character(0))

need(expr, message = paste(label, "must be provided"), label)

A list of tests. Each test should equal NULL for success, FALSE for silent failure, or a string for failure with an error message.
A CSS class to apply. The actual CSS string will have shiny-output-error- prepended to this value.
An expression to test. The condition will pass if the expression meets the conditions spelled out in Details.
A message to convey to the user if the validation condition is not met. If no message is provided, one will be created using label. To fail with no message, use FALSE for the message.
A human-readable name for the field that may be missing. This parameter is not needed if message is provided, but must be provided otherwise.

The validate function takes any number of (unnamed) arguments, each of which represents a condition to test. If any of the conditions represent failure, then a special type of error is signaled which stops execution. If this error is not handled by application-specific code, it is displayed to the user by Shiny.

An easy way to provide arguments to validate is to use the need function, which takes an expression and a string; if the expression is considered a failure, then the string will be used as the error message. The need function considers its expression to be a failure if it is any of the following:

NULL "" An empty atomic vector An atomic vector that contains only missing values A logical vector that contains all FALSE or missing values An object of class "try-error" A value that represents an unclicked actionButton



  • need
  • validate
# in ui.R
  checkboxGroupInput('in1', 'Check some letters', choices = head(LETTERS)),
  selectizeInput('in2', 'Select a state', choices =,

# in server.R
function(input, output) {
  output$plot <- renderPlot({
      need(input$in1, 'Check at least one letter!'),
      need(input$in2 != '', 'Please choose a state.')
    plot(1:10, main = paste(c(input$in1, input$in2), collapse = ', '))
Documentation reproduced from package shiny, version 0.12.2, License: GPL-3 | file LICENSE

Community examples

Looks like there are no examples yet.