shinycssloaders icon indicating copy to clipboard operation
shinycssloaders copied to clipboard

Showing spinner in a setTimeout function to avoid blinking spinners

Open rgriffogoes opened this issue 4 years ago • 4 comments

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

rgriffogoes avatar Apr 02 '21 21:04 rgriffogoes

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.

daattali avatar Oct 10 '21 00:10 daattali

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

rgriffogoes avatar Jan 11 '22 22:01 rgriffogoes

@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 avatar Mar 05 '23 21:03 daattali

@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?

daattali avatar May 08 '23 19:05 daattali