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)