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

Support progress indicators #22

Open
kamilzyla opened this issue Jul 9, 2021 · 2 comments
Open

Support progress indicators #22

kamilzyla opened this issue Jul 9, 2021 · 2 comments
Labels

Comments

@kamilzyla
Copy link
Collaborator

With Shiny it is possible to report progress of a long running computation (using either the functional or object-oriented API). Many React libraries provide components which could be used instead (e.g. Spinner and ProgressIndicator from Fluent UI), however it is difficult to use them as Shiny is super vigilant about delaying any rendering until all computations are finished. It is possible to hack around this problem to some extent, e.g.:

library(shiny)
library(shiny.fluent)

shinyApp(
  ui = Stack(tokens = list(childrenGap = 10), style = list(width = 200),
    PrimaryButton.shinyInput("start", text = "Start Computation"),
    reactOutput("spinner")
  ),
  server = function(input, output) {
    computing <- reactiveVal(FALSE)
    trigger <- debounce(computing, 5) # Enough delay for Shiny to render the Spinner first
    observeEvent(input$start, computing(TRUE))
    observeEvent(trigger(), {
      if (trigger()) {
        Sys.sleep(3) # Long computation
        computing(FALSE)
      }
    })
    output$spinner <- renderReact({
      if (computing()) Spinner(size = 3)
    })
  }
)

Still, this is far from being a drop-in replacement for the progress reporting functionality in base Shiny.

@kamilzyla
Copy link
Collaborator Author

kamilzyla commented Aug 4, 2022

It would be great to be able to use progress indicators in a similar fashion to this (Slack discussion):

plotly::plotlyOutput("plot") |> shinycssloaders::withSpinner()

@OrangeIcecubes
Copy link

Thanks for sharing, very helpful

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

No branches or pull requests

2 participants