Is there a way to insert shiny progress function (incProgress) inside the pblapply function so that it would show the progress in percentages in the upper right corner. IncProgress(...) needs to be evaluated every time the lapply function starts again, just like in the text based progress bar the console is updated.
Here is my test example:
runApp(list(
ui = shinyUI(
fluidPage(
actionButton("calc","Start calculation"),
dataTableOutput("out")
)
),
server = shinyServer(function(session, input, output) {
library(pbapply)
#create list
n <- 100; nn <- 1000
g <- factor(round(n * runif(n * nn)))
x <- rnorm(n * nn) + sqrt(as.numeric(g))
xg <- split(x, g)
observeEvent(input$calc > 0,{
withProgress(message = "Initializing data manipulation process", value=0, {
list = pblapply(xg,mean)
#insert 'incProgress(percentage, detail = paste0("Progress: ",percentage)' in the pbapply or txtProgress function
})
output$out = renderDataTable(datatable(as.data.frame(unlist(list))))
})
})
)
)
I don't know if you can get the percentage from pblapply
but you in the withProgress
could do:
percentage <- 0
list = pblapply(xg,function(x) {
Sys.sleep(0.05);
percentage <<- percentage + 1/length(xg)*100
incProgress(1/length(xg), detail = paste0("Progress: ",round(percentage,2)))
mean(x);
})
I added the Sys.sleep
to slow the loop down. You can use lapply
if you don't need to see the progress in the R console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With