shiny icon indicating copy to clipboard operation
shiny copied to clipboard

When the withProgress is closed, the program still runs in the background.

Open SEvisual opened this issue 11 months ago • 3 comments

When the withProgress is closed, the program still runs in the background. I don't know if it's a bug, if not can add this feature? this is a example in 《Mastering Shiny》.

library(shiny)
ui <- fluidPage(
    numericInput("steps", "How many steps?", 10),
    actionButton("go", "go"),
    textOutput("result")
)

server <- function(input, output, session) {
    data <- eventReactive(input$go, {
        withProgress(message = "Computing random number", {
            for (i in seq_len(input$steps)) {
                Sys.sleep(0.5)
                incProgress(1 / input$steps)
            }
            runif(1)
        })
    })
    
    output$result <- renderText(round(data(), 2))
}
shinyApp(ui, server)

Thanks!

SEvisual avatar Feb 29 '24 01:02 SEvisual

the program still runs in the background.

I'm not sure I understand what you're referring to here. The example appears to work as expected for me. Could you please be more precise about what you're observing and how you expect it to be different?

cpsievert avatar Feb 29 '24 15:02 cpsievert

I think @bioinformzhang is wanting the task/process to be cancelled when the progress message is closed.

gadenbuie avatar Feb 29 '24 15:02 gadenbuie

Yep, when I close the progress bar(message) in the lower right corner, the program is still running in the background, as shown in the example 0.85

https://github.com/rstudio/shiny/assets/114212003/0e4afb42-6c3c-444d-ae24-b79422d33cfc

SEvisual avatar Mar 04 '24 02:03 SEvisual