I have an application in R's Shiny. I would like to handle messages so that users do not see what error occurred. I know that via
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),
I can disable error messages entirely, but I would like to show users one message like
An error occurred. Please contact the admin.
whenever message of whatever type occurs (and still keep the original error message in the log). Any ideas?
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.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 justbase::stop(e)
, wheree
is an error string or object with class 'error'.Reference: https://shiny.rstudio.com/articles/sanitize-errors.html