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

options to use spinners with conditional panels? #58

Closed tnelsen closed 3 years ago

tnelsen commented 3 years ago

Hi!

I have a graph that is the result of several models and takes a long time to load. I only want to calculate and render it when the user checks a box (or something similar). I am using the cssspinners and they work the first time the graph is rendered but if the box is unchecked and then checked again the spinners do not show up. From, https://github.com/daattali/shinycssloaders/issues/7 it seems like the spinners do not play well with conditional panels. Are there other options that you would suggest?

Reproducible example:

ui <- fluidPage( checkboxInput(inputId = "render_graph", label = "Render graph", value = TRUE), conditionalPanel(condition = "input.render_graph == 1", shinycssloaders::withSpinner( plotlyOutput("example_plot"), type = 6, color="#005fae")) )

server <- function(input, output){ output$example_plot <- renderPlotly({ req(input$render_graph) Sys.sleep(3) plot_ly(data = data.frame(x = 1:10, y = 1:10), x = ~x, y = ~y, type = 'scatter', mode = 'markers') }) }

shinyApp(ui, server)

daattali commented 3 years ago

I can't reproduce the issue. I tried on 3 different machines running different versions of R. The code you provided works after adding the relevant library() calls. Can you please verify that this exact code causes an issue with the latest shinycssloaders version?

tnelsen commented 3 years ago

Thanks for looking at this. I wasn't running the newest version bc of conflicts with another package but have it working now.