Reactive Expressions: Propagated Errors
Errors are propagated through the reactive graph just as values, but they present different behavior when they reach an:
- Output: The error will be displayed in the app.
- Observer: The error will cause the current session to terminate.
- This can be avoided by wrapping the code in
try()
ortryCatch()
functions.
- This can be avoided by wrapping the code in
From: examples/15-reactive-blocks/01-error-propagated-example.R
library(shiny)
ui <- fluidPage(
checkboxInput("error", "error?"),
textOutput("result")
)
server <- function(input, output, session) {
a <- reactive({
if (input$error) {
stop("Error!")
} else {
1
}
})
b <- reactive(a() + 1)
c <- reactive(b() + 1)
output$result <- renderText(c())
}
shinyApp(ui, server)