| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/utils.R |
| 3 |
\name{safeError} |
| 4 |
\alias{safeError} |
| 5 |
\title{Declare an error safe for the user to see} |
| 6 |
\usage{ |
| 7 |
safeError(error) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{error}{Either an "error" object or a "character" object (string). |
| 11 |
In the latter case, the string will become the message of the error |
| 12 |
returned by \code{safeError}.} |
| 13 |
} |
| 14 |
\value{ |
| 15 |
An "error" object |
| 16 |
} |
| 17 |
\description{ |
| 18 |
This should be used when you want to let the user see an error |
| 19 |
message even if the default is to sanitize all errors. If you have an |
| 20 |
error \code{e} and call \code{stop(safeError(e))}, then Shiny will |
| 21 |
ignore the value of \code{getOption("shiny.sanitize.errors")} and always |
| 22 |
display the error in the app itself. |
| 23 |
} |
| 24 |
\details{ |
| 25 |
An error generated by \code{safeError} has priority over all |
| 26 |
other Shiny errors. This can be dangerous. For example, if you have set |
| 27 |
\code{options(shiny.sanitize.errors = TRUE)}, then by default all error |
| 28 |
messages are omitted in the app, and replaced by a generic error message. |
| 29 |
However, this does not apply to \code{safeError}: whatever you pass |
| 30 |
through \code{error} will be displayed to the user. So, this should only |
| 31 |
be used when you are sure that your error message does not contain any |
| 32 |
sensitive information. In those situations, \code{safeError} can make |
| 33 |
your users' lives much easier by giving them a hint as to where the |
| 34 |
error occurred. |
| 35 |
} |
| 36 |
\examples{ |
| 37 |
## Only run examples in interactive R sessions |
| 38 |
if (interactive()) { |
| 39 |
|
| 40 |
# uncomment the desired line to experiment with shiny.sanitize.errors |
| 41 |
# options(shiny.sanitize.errors = TRUE) |
| 42 |
# options(shiny.sanitize.errors = FALSE) |
| 43 |
|
| 44 |
# Define UI |
| 45 |
ui <- fluidPage( |
| 46 |
textInput('number', 'Enter your favorite number from 1 to 10', '5'), |
| 47 |
textOutput('normalError'), |
| 48 |
textOutput('safeError') |
| 49 |
) |
| 50 |
|
| 51 |
# Server logic |
| 52 |
server <- function(input, output) { |
| 53 |
output$normalError <- renderText({ |
| 54 |
number <- input$number |
| 55 |
if (number \%in\% 1:10) { |
| 56 |
return(paste('You chose', number, '!')) |
| 57 |
} else { |
| 58 |
stop( |
| 59 |
paste(number, 'is not a number between 1 and 10') |
| 60 |
) |
| 61 |
} |
| 62 |
}) |
| 63 |
output$safeError <- renderText({ |
| 64 |
number <- input$number |
| 65 |
if (number \%in\% 1:10) { |
| 66 |
return(paste('You chose', number, '!')) |
| 67 |
} else { |
| 68 |
stop(safeError( |
| 69 |
paste(number, 'is not a number between 1 and 10') |
| 70 |
)) |
| 71 |
} |
| 72 |
}) |
| 73 |
} |
| 74 |
|
| 75 |
# Complete app with UI and server components |
| 76 |
shinyApp(ui, server) |
| 77 |
} |
| 78 |
} |
| 79 |
\seealso{ |
| 80 |
\code{\link[=shiny-options]{shiny-options()}} |
| 81 |
} |