updated customStop() documentation example to match Winston's pattern

This commit is contained in:
Barbara Borges Ribeiro
2016-04-06 14:08:11 +01:00
parent a692b3ced8
commit 477d46316e
2 changed files with 33 additions and 25 deletions

View File

@@ -904,29 +904,31 @@ columnToRowData <- function(data) {
#'
#' @seealso \code{\link{shiny-options}}
#'
#' @export
#' @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)
#'
#' # ui
#' ui <- shinyUI(fluidPage(
#' # Define UI
#' ui <- fluidPage(
#' textInput('number', 'Enter your favorite number from 1 to 10', '5'),
#' textOutput('errorStop'),
#' textOutput('errorCustomStop')
#' ))
#' )
#'
#' # server
#' server <- shinyServer(function(input, output) {
#' # Server logic
#' server <- function(input, output) {
#' output$errorStop <- renderText({
#' number <- input$number
#' if (number %in% 1:10) {
#' return(paste('You chose', number, '!'))
#' } else {
#' return(stop(
#' stop(
#' paste(number, 'is not a number between 1 and 10')
#' ))
#' )
#' }
#' })
#' output$errorCustomStop <- renderText({
@@ -934,15 +936,17 @@ columnToRowData <- function(data) {
#' if (number %in% 1:10) {
#' return(paste('You chose', number, '!'))
#' } else {
#' return(customStop(
#' customStop(
#' paste(number, 'is not a number between 1 and 10')
#' ))
#' )
#' }
#' })
#' })
#' }
#'
#' # run
#' if (interactive()) shinyApp(ui = ui, server = server)
#' # Complete app with UI and server components
#' shinyApp(ui, server)
#' }
#' @export
customStop <- function(error, errorClass = character(0)) {
if (inherits(error, "error")) {
class(error) <- c("shiny.custom.error", errorClass, class(error))