Files
shiny/man/customStop.Rd
2016-04-06 14:08:11 +01:00

81 lines
2.4 KiB
R

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{customStop}
\alias{customStop}
\title{Create a custom error}
\usage{
customStop(error, errorClass = character(0))
}
\arguments{
\item{error}{Either an "error" object or a "character" object (string).
The former will just be rethrown, while the latter will be used as the
message of the error returned by \code{customStop}.}
\item{errorClass}{An optional class to add to the error.}
}
\description{
This should be used when you want to create a custom error to which error
default options do not apply. In particular, \code{customStop} will
ignore the value of \code{getOption("shiny.sanitize.errors")} and always
display the error in the app itself.
}
\details{
An error generated by \code{customStop} has priority over all
other Shiny errors. This can be dangerous. For example, if you have set
\code{options(shiny.sanitize.errors = TRUE)}, then by default all error
messages are omitted in the app, and replaced by a generic error message.
However, this does not apply to \code{customStop}: whatever you pass
through \code{error} will be displayed to the user. So, this should only
be used when you are sure that your error message does not contain any
sensitive information. In those situations, \code{customStop} can make
your users' lives much easier by giving them a hint as to where the
error occurred.
}
\examples{
## Only run examples in interactive R sessions
if (interactive()) {
# uncomment the desired line to experiment with shiny.sanitize.errors
# options(shiny.sanitize.errors = TRUE)
# options(shiny.sanitize.errors = FALSE)
# Define UI
ui <- fluidPage(
textInput('number', 'Enter your favorite number from 1 to 10', '5'),
textOutput('errorStop'),
textOutput('errorCustomStop')
)
# Server logic
server <- function(input, output) {
output$errorStop <- renderText({
number <- input$number
if (number \%in\% 1:10) {
return(paste('You chose', number, '!'))
} else {
stop(
paste(number, 'is not a number between 1 and 10')
)
}
})
output$errorCustomStop <- renderText({
number <- input$number
if (number \%in\% 1:10) {
return(paste('You chose', number, '!'))
} else {
customStop(
paste(number, 'is not a number between 1 and 10')
)
}
})
}
# Complete app with UI and server components
shinyApp(ui, server)
}
}
\seealso{
\code{\link{shiny-options}}
}