diff --git a/R/utils.R b/R/utils.R index 8e1844102..ea83f3a5f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1092,15 +1092,16 @@ reactiveStop <- function(message = "", class = NULL) { #' \code{shiny-output-error-} prepended to this value. #' @export #' @examples -#' # in ui.R -#' fluidPage( +#' ## Only run examples in interactive R sessions +#' if (interactive()) { +#' +#' ui <- fluidPage( #' checkboxGroupInput('in1', 'Check some letters', choices = head(LETTERS)), #' selectizeInput('in2', 'Select a state', choices = state.name), #' plotOutput('plot') #' ) #' -#' # in server.R -#' function(input, output) { +#' server <- function(input, output) { #' output$plot <- renderPlot({ #' validate( #' need(input$in1, 'Check at least one letter!'), @@ -1109,6 +1110,10 @@ reactiveStop <- function(message = "", class = NULL) { #' plot(1:10, main = paste(c(input$in1, input$in2), collapse = ', ')) #' }) #' } +#' +#' shinyApp(ui, server) +#' +#' } validate <- function(..., errorClass = character(0)) { results <- sapply(list(...), function(x) { # Detect NULL or NA diff --git a/man/validate.Rd b/man/validate.Rd index 1d368da13..befa4831d 100644 --- a/man/validate.Rd +++ b/man/validate.Rd @@ -78,15 +78,16 @@ not necessary for the outputs to validate \code{input$x} explicitly, as long as \code{a} does validate it. } \examples{ -# in ui.R -fluidPage( +## Only run examples in interactive R sessions +if (interactive()) { + +ui <- fluidPage( checkboxGroupInput('in1', 'Check some letters', choices = head(LETTERS)), selectizeInput('in2', 'Select a state', choices = state.name), plotOutput('plot') ) -# in server.R -function(input, output) { +server <- function(input, output) { output$plot <- renderPlot({ validate( need(input$in1, 'Check at least one letter!'), @@ -95,5 +96,9 @@ function(input, output) { plot(1:10, main = paste(c(input$in1, input$in2), collapse = ', ')) }) } + +shinyApp(ui, server) + +} }