I used Shiny's withProgress feature for a long calculation: https://shiny.rstudio.com/reference/shiny/latest/withProgress.html
However, it simply puts the system to sleep and I have to wait for the Sys.sleep(xx) to finish before the calculations are actually undertaken. So I don't see the point of using something that makes the calculation process seem twice as long.
Is there some other progress bar approach that doesn't use Sys.sleep(0.25) so that calculations are actually occurring during the progress status display?
You should not do Sys.sleep(0.25)
there, that is just an example to make the progress bar work.
If you have a function that has to sum `10.000.000 random numbers 15 times for example, you could do:
ui <- fluidPage(
plotOutput("plot")
)
server <- function(input, output) {
output$plot <- renderPlot({
withProgress(message = 'Calculation in progress',
detail = 'This may take a while...', value = 0, {
for (i in 1:15) {
incProgress(1/15)
sum(runif(10000000,0,1))
}
})
plot(cars)
})
}
shinyApp(ui, server)
Second example:
library(shiny)
ui <- fluidPage(
plotOutput("plot")
)
test_fun <- function()
{
for (i in 1:15) {
incProgress(1/15)
sum(runif(10000000,0,1))
}
}
server <- function(input, output) {
output$plot <- renderPlot({
withProgress(message = 'Calculation in progress',
detail = 'This may take a while...', value = 0, {
test_fun()
})
plot(cars)
})
}
shinyApp(ui, server)
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