Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

rgriffogoes
Copy link

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
Copy link
Owner

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
Copy link
Author

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

@daattali
Copy link
Owner

daattali commented Mar 5, 2023

@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
Copy link
Owner

daattali commented May 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants