mirror of
https://github.com/rstudio/shiny.git
synced 2026-02-14 16:45:15 -05:00
updated customStop() documentation example to match Winston's pattern
This commit is contained in:
30
R/utils.R
30
R/utils.R
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user