progress2: 'Shiny' progress bar, but can run without reactive context

Description Usage Arguments Value Examples

View source: R/shiny-progress.R

Description

'Shiny' progress bar, but can run without reactive context

Usage

1
2
3
4
5
6
7
8
9
progress2(
  title,
  max = 1,
  ...,
  quiet = FALSE,
  session = shiny::getDefaultReactiveDomain(),
  shiny_auto_close = FALSE,
  log = NULL
)

Arguments

title

character, task description

max

maximum number of items in the queue

...

passed to shiny::Progress$new(...)

quiet

suppress console output, ignored in shiny context.

session

'shiny' session, default is current reactive domain

shiny_auto_close

logical, automatically close 'shiny' progress bar once current observer is over. Default is FALSE. If setting to TRUE, then it's equivalent to p <- progress2(...); on.exit({p$close()}, add = TRUE).

log

function when running locally, default is NULL, which redirects to cat2

Value

A list of functions:

inc(detail, message = NULL, amount = 1, ...)

Increase progress bar by amount (default is 1).

close()

Close the progress

reset(detail = '', message = '', value = 0)

Reset the progress to value (default is 0), and reset information

get_value()

Get current progress value

is_closed()

Returns logical value if the progress is closed or not.

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
progress <- progress2('Task A', max = 2)
progress$inc('Detail 1')
progress$inc('Detail 2')
progress$close()

# Check if progress is closed
progress$is_closed()

# ------------------------------ Shiny Example ------------------------------
library(shiny)
library(dipsaus)

ui <- fluidPage(
  actionButtonStyled('do', 'Click Here', type = 'primary')
)

server <- function(input, output, session) {
  observeEvent(input$do, {
    updateActionButtonStyled(session, 'do', disabled = TRUE)
    progress <- progress2('Task A', max = 10, shiny_auto_close = TRUE)
    lapply(1:10, function(ii){
      progress$inc(sprintf('Detail %d', ii))
      Sys.sleep(0.2)
    })
    updateActionButtonStyled(session, 'do', disabled = FALSE)
  })
}

if(interactive()){
  shinyApp(ui, server)
}

dipsaus documentation built on Sept. 6, 2021, 5:08 p.m.