fmUpdateProgress: Update progress of the background process

Description Usage Arguments Value Examples

View source: R/utils.R

Description

This function allows to pass progress info from the background process to the main process, i.e. to display a progress in the application

Usage

1
fmUpdateProgress(task, progress = 0, msg = NULL)

Arguments

task

task object

progress

numeric in range 0..1

msg

character string, message that will be displayed in the progress bar

Value

No return value, called for side effects.

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
if (interactive()) {
  library(shiny)
  plan(fmParallelStrategy())
  
  longFun <- function(task, n){
    for (i in seq_len(10)){
      if (fmIsInterrupted(task)) return()
      fmUpdateProgress(task, progress = i/10, msg = "busy...")
      Sys.sleep(1)
    }
    n
  }
  
  shinyApp(
    ui = basicPage(
      uiOutput("button"), 
      numericInput("n", "n", -3, -5, 5), 
      textOutput("result")
    ),
    server = function(input, output, session){
      fm <- FutureManager$new(input, session)
      output$button <- renderUI(fmRunButton("run", fm))
      Res <- reactiveVal()
      Args <- reactive(list(n = input$n))
      fm$registerRunObserver("run", "Progress", Res, longFun, Args)
      output$result <- renderText({
        res <- Res()
        fmValidate(res)
        fmGetValue(res)
      })
    }
  )
}

Boehringer-Ingelheim/FutureManager documentation built on June 16, 2021, 6:23 p.m.