Learn R Programming

progressr (version 0.6.0)

withProgressShiny: Use Progressr in Shiny Apps: Plug-in Backward Compatibility Replacement for shiny::withProgress()

Description

Use Progressr in Shiny Apps: Plug-in Backward Compatibility Replacement for shiny::withProgress()

Usage

withProgressShiny(
  expr,
  ...,
  env = parent.frame(),
  quoted = FALSE,
  handlers = c(shiny = handler_shiny, progressr::handlers(default = NULL))
)

Arguments

expr, …, env, quoted

Arguments passed to shiny::withProgress as is.

handlers

Zero or more progression handlers used to report on progress.

Value

The value of shiny::withProgress.

Requirements

This function requires the shiny package.

Examples

Run this code
# NOT RUN {
library(shiny)
library(progressr)

app <- shinyApp(
  ui = fluidPage(
    plotOutput("plot")
  ),

  server = function(input, output) {
    output$plot <- renderPlot({
      X <- 1:15
      withProgressShiny(message = "Calculation in progress",
                        detail = "This may take a while ...", value = 0, {
        p <- progressor(along = X)
        y <- lapply(X, FUN=function(x) {
          p()
          Sys.sleep(0.25)
        })
      })
      
      plot(cars)

      ## Terminate the Shiny app
      Sys.sleep(1.0)
      stopApp(returnValue = invisible())
    })
  }
)

local({
  oopts <- options(device.ask.default = FALSE)
  on.exit(options(oopts))
  if (interactive()) print(app)
})
# }

Run the code above in your browser using DataLab