Reactive Expressions: Errors seq()

If some error is present in next function:

  • Observers and outputs to stop what they’re doing but not otherwise fail.
  • By default, it will cause outputs to reset to their initial blank state, unless req(..., cancelOutput = TRUE) they’ll preserve their current display.

From: examples/15-reactive-blocks/02-seq-error-example.R

library(shiny)

ui <- fluidPage(
  titlePanel("req() function example"),
  sidebarLayout(
    sidebarPanel(
      numericInput("num", "Enter a number:", value = NULL),
      checkboxInput("cancelOutput","Cancel Output")
    ),
    mainPanel(
      plotOutput("hist")
    )
  )
)

server <- function(input, output) {
  output$hist <- renderPlot({
    req(input$num > 0, cancelOutput = input$cancelOutput)
    hist(rnorm(input$num))
  })
}

shinyApp(ui = ui, server = server)