I am developing a Shiny app where I split time consuming calculation to multiple session using furrr::
and future
. I would like to update the progress bar after every (or every n) calculations. The below example I found updates the progress bar but only once a session has been fully completed. This means that the 6 updates happen almost simultaneously at the end. For the non-Shiny version there is the argument .progress = T
which leads to the updates I would like (see second example).
Is there something similar which could be used for a shiny progress bar? It would even be fine if the updates just depend on the first worker since the calculation is almost the same for all workers.
Thanks for any help in advance!
Example 1:
library(shiny)
library(progressr)
app <- shinyApp(
ui = fluidPage(
plotOutput("plot")
),
server = function(input, output) {
output$plot <- renderPlot({
X <- 1:24
future::plan(future::multisession(workers = 6))
withProgressShiny(message = "Calculation in progress",
detail = "This may take a while ...", value = 0, {
p <- progressor(along = X)
y <- furrr::future_map(X, function(x) {
Sys.sleep(1)
p()
})
})
plot(cars)
})
}
)
Example 2:
X <- 1:24
future::plan(future::multisession(workers = 6))
y <-
furrr::future_map(X, function(x) {Sys.sleep(1)
p()
}, .progress = T)
future::plan(future::sequential())