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

Showing spinner in a setTimeout function to avoid blinking spinners #62

Open rgriffogoes opened 3 years ago

rgriffogoes commented 3 years ago

Adding configurable delay (show.delay property) before showing spinner (and if a hide comes before delay, it doesn't show at all).

Default values should behave almost* the same as before: with a 0 delay timeout function it can be that the show/hide cycle behaves differently, but on my understanding it would behave better (e.g.: if somehow the hide spinner happens immediately after the display, nothing will happen while before the change the dom would be affected twice)

Split from pull request #61

Added one more button to example, to allow a test where only the data is updated - setting sleep time to 0 one can see how the show.delay can be used

daattali commented 2 years ago

Thanks for the PR @rgriffogoes !

I just tried this out locally, and it seems like the spinner doesn't show up in the initial load. Does this happen to you too? Example app:

shinyApp(
  ui = fluidPage(
    actionButton("go", "Go"),
    withSpinner(plotOutput("plot"), show.delay = 500)
  ),
  server = function(input, output) {
    output$plot <- renderPlot({
      input$go
      Sys.sleep(1.5)
      plot(runif(10))
    })
  }
)

The spinner doesn't show up at all the first time, and afterwards it works correctly.

rgriffogoes commented 2 years ago

Took some time to find time but the "first time" showing issue is fixed @daattali

daattali commented 1 year ago

@rgriffogoes I apologize for leaving this for so long. I do like this PR, the only thing I want to change is that when the delay is 0 (which will be the most common), I prefer not to have to use a javascript setTimeout(). Just run immediately with a timeout of 0. And also add some documentation about the parameter.

Thanks!

daattali commented 1 year ago

@rgriffogoes I would love to include this feature. This package had a lot of work done on it recently, would you be willing to comtinue this PR?