daattali / shinycssloaders

⌛ Add loading animations to a Shiny output while it's recalculating
https://daattali.com/shiny/shinycssloaders-demo/
Other
395 stars 45 forks source link

Infinite spinner on req(cancelOutput = TRUE) #71

Closed bartekch closed 1 year ago

bartekch commented 2 years ago

When there is an output with spinner and somewhere in its reactive dependencies the processing is stopped by req(..., cancelOutput = TRUE), spinner will never disappear. In the following app this is happening when the box is unchecked and data is recalculated. The previous output is still there, but the spinner won't hide back.

library(shiny)
library(shinycssloaders)

shinyApp(
  ui = basicPage(
    checkboxInput("is_correct", "Is data correct?", TRUE),
    actionButton("recalculate", "Recalculate data"),

    shinycssloaders::withSpinner(
      tableOutput("table")
    )
  ),

  server = function(input, output, session) {
    output$table <- renderTable({
      input$recalculate
      Sys.sleep(1)
      req(isolate(input$is_correct), cancelOutput = TRUE)
      data.frame(x = rnorm(5))
    })
  }
)

I guess it could not be trivial to fix, but anyway, it would be nice to have spinner hidden in such cases.

daattali commented 1 year ago

Thanks for the report. After investigating the issue, I think it stems from the fact that shiny never triggers an "error" event when cancelOutput is used.

I filed an issue with shiny https://github.com/rstudio/shiny/issues/3787 and hopefully this will be fixed automatically when it's fixed in shiny.

daattali commented 1 year ago

I'm closing this issue because there's not much to do on our end. This will automatically be fixed when shiny fixes their bug.