Shiny : showing one message for all errors

Interesting question. I only thought about it for one minute so I'm sure there are better, cleaner solutions that use R code, but here's a CSS solution since you used CSS in the question

Basically, since I saw that you used a :before, it made me realize that you can just change the text of that pseudoelement.

runApp(shinyApp(
  ui = fluidPage(
    tags$style(type="text/css",
               ".shiny-output-error { visibility: hidden; }",
               ".shiny-output-error:before { visibility: visible; content: 'An error occurred. Please contact the admin.'; }"
    ),
    textOutput("text")
  ),
  server = function(input, output, session) {
    output$text <- renderText({
      stop("lalala")
    })
  }
))

You can add options(shiny.sanitize.errors = TRUE) somewhere in your app. All error messages will then be replaced with the generic error message:

Error: An error has occurred. Check your logs or contact the app author for clarification.

If you do want a particular error to pass through unsanitised, you can use base::stop(shiny::safeError(e)) instead of just base::stop(e), where e is an error string or object with class 'error'.

Reference: https://shiny.rstudio.com/articles/sanitize-errors.html

Tags:

R

Shiny