withProgressShiny: Use Progressr in Shiny Apps: Plug-in Backward Compatibility...

Description Usage Arguments Value Requirements Examples

View source: R/withProgressShiny.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
withProgressShiny(
  expr,
  ...,
  message = NULL,
  detail = NULL,
  inputs = list(message = NULL, detail = "message"),
  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.

message, detail

(character string) The message and the detail message to be passed to shiny::withProgress().

inputs

(named list) Specifies from what sources the Shiny progress elements 'message' and 'detail' should be updated. Valid sources are "message", "sticky_message" and "non_sticky_message", where "message" is short for c("non_sticky_message", "sticky_message"). For example, inputs = list(message = "sticky-message", detail = "message") will update the Shiny 'message' component from sticky messages only, whereas the 'detail' component is updated using any message.

handlers

Zero or more progression handlers used to report on progress.

Value

The value of shiny::withProgress.

Requirements

This function requires the shiny package and will use the handler_shiny() progressr handler internally to report on updates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 = "Starting ...",
                        value = 0, {
        p <- progressor(along = X)
        y <- lapply(X, FUN=function(x) {
          Sys.sleep(0.25)
          p(sprintf("x=%d", x))
        })
      })
      
      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)
})

Example output



progressr documentation built on Sept. 24, 2021, 5:07 p.m.