2

I'm using the R package future to run a large compute job. I would like to parallelize the job across three cores and have a separate progress bar for each core. I would also like the script to wait until all three cores are done before displaying the Done! message.

Right now the Done! message appears while the cores are still running. If I use a function like resolved then the progress bars show 0% until the three cores are done and then immediately skip to 100%. How can I update progress and wait for completion at the same time?

For context, I'm uploading a large number of files to AWS S3.

library(shiny)
library(future)
plan(multiprocess)

ui <- fluidPage(
    actionButton("run","Run")
)

server <- function(input, output, session) {
    
    observeEvent(input$run, {
        # Start three parallel processes.
        progress <- list()
        for(k in 1:3) {
            progress[[k]] <- AsyncProgress$new(session, min=1, max=15)
            future({
                for (i in 1:15) {
                    progress[[k]]$set(value = i)
                    Sys.sleep(0.5)
                }
                progress[[k]]$close()
            })
        }
        # Show notification when all three processes are done.
        showNotification("Done!", type = "error") # this runs too early
    })
    
}

shinyApp(ui, server)
Jeff Bezos
  • 1,929
  • 13
  • 23
  • The [quick-start guide](http://htmlpreview.github.io/?https://github.com/fellstat/ipc/blob/master/inst/doc/shinymp.html) of the ipc-package gives an example of what you are asking for: AsyncProgress. – ismirsehregal Jul 19 '21 at 17:36
  • Are you referring to the `Changing a reactive value from a future` example? It looks like they're using `renderTable()` to wait for the output. I'm curious if there's a way to do this within a reactive expression. For example, wait until cores finish running before move on to the next line. – Jeff Bezos Jul 19 '21 at 17:47
  • Just below the example you mentioned, you'll find another one called: *Adding a progress bar to an async operation*. Please also see [this](https://stackoverflow.com/questions/52863720/async-display-progress-when-actionbutton-is-hit-and-disable-other-operations-fo). – ismirsehregal Jul 19 '21 at 17:55

0 Answers0