I'm trying to create a Shiny app that displays incremental step updates with 1-second delays between steps. While the code logic works in regular R scripts, it fails to show intermediate steps in Shiny - only the final result appears.
After clicking "Run!", the output should display "step1" "step2" "step3" step-by-step. But actually, they comes out all together.
here is my code:
library(shiny)
ui <- fluidPage(
actionButton("run", "Run!"),
textOutput("out")
)
server <- function(input, output, session) {
data <- reactiveVal("step0")
output$out <- renderText(
data()
)
observeEvent(input$run, {
for (i in 1:3) {
Sys.sleep(1)
data(paste0(isolate(data()), "\n step", i))
output$out <- renderText(
data()
)
}
})
}
shinyApp(ui, server)
It looks like the UI freezes and only shows the final result
Thanks!!!