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

Shiny render plots asynchronously as soon as they are ready #83

Closed LuShuYangMing closed 10 months ago

LuShuYangMing commented 10 months ago

Is possible to render plotlyOutput("plot1")%>%withspinner() asynchronously / completely independently from plotlyOutput("plot2")%>%withspinner()? Right now I have used future_promise in shiny on plot1 and plot2, respectively. I have to wait for both of them to complete all processes to render the final shiny app as a single monolithic output. Ideally all visuals have 'withSpinner' loading icons and load independently.

daattali commented 10 months ago

This is not currently possible. I'm not sure if it's even technically possible (maybe it is with async, I'm not sure). Can you share your code that you're using to get plot1 and plot2 to render independently?

LuShuYangMing commented 10 months ago

Thank you for your reply, here is the code. Now I test the code without future_promise, but it still load simultaneously in the same html page, but not asynchronously.

library(shiny)
library(shinycssloaders)

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

    output$plot2 <- renderPlot({
      input$go
      Sys.sleep(5)
      plot(runif(10))
    })
  }
)

I need plot1 showed after 1s and plot2 showed after 5s, but now both of them are showed after 5s.

daattali commented 10 months ago

Putting the css loaders aside, both plots show up at the same time. If you have a way to have the plots to render at different times, then I can try to look into having shinycssloaders support that. But the code that you provided has both plots showing up together, so this is currently a shiny issue, not a shinycssloaders issue.

Do you have code for getting the two plots to render independently, at different times?

LuShuYangMing commented 10 months ago

Putting the css loaders aside, both plots show up at the same time. If you have a way to have the plots to render at different times, then I can try to look into having shinycssloaders support that. But the code that you provided has both plots showing up together, so this is currently a shiny issue, not a shinycssloaders issue.

Sorry, most of our html pages have more than two plot. Thus, my needing is that if one plot done, show it without any waiting. Do you have any other suggestions or links to solve this problem?

daattali commented 10 months ago

Again, that's not a shinycssloaders question, that's a general shiny question. Your issue isn't with the lodaing icons, your issue is with shiny not rendering an output as soon as it's finished.

I'm closing this issue as it's off topic. Your question is a shiny question, please ask it in a shiny specific forum.