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

AutoWaiter in ShinyModules shows not on all modules at the same time #133

Open
DavZim opened this issue Feb 2, 2023 · 0 comments
Open

Comments

@DavZim
Copy link

DavZim commented Feb 2, 2023

When I have a shiny app with multiple modules, autoWaiter does not pick up all elements at the same time but only "hides" the second element when the first one is done rendering.

MWE - autoWaiter in main UI

library(shiny)
library(waiter)
sleep <- function(id) {
  cat("ID =", id, ":\n")
  for (i in seq(2)) cat(Sys.sleep(1), i, "\n")
}

UI <- function(id) {
  ns <- NS(id)
  column(width = 4, "mod =", id,
         plotOutput(ns("plot"), width = "300px", height = "300px"))
}

Server <- function(id, data) {
  moduleServer(
    id,
    function(input, output, session) {
      data_plot <- reactive({
        sleep(id)
        data
      })
      
      output$plot <- renderPlot({
        plot(data_plot()$x, data_plot()$y)
      })
    }
  )
}

ui <- fluidPage(
  useWaiter(),
  autoWaiter(),
  fluidRow(
    column(width = 4, "mod = main-ui",
           plotOutput("plot", width = "300px", height = "300px")),
    UI("mod1"),
    UI("mod2")
  )
)

server <- function(input, output, session) {
  Server("mod1", iris[, c("Sepal.Width", "Sepal.Length")] |> setNames(c("x", "y")))
  Server("mod2", mtcars[, c("wt", "mpg")] |> setNames(c("x", "y")))
  
  output$plot <- renderPlot({
    sleep("main-ui")
    plot(1:10, rnorm(10))
  })
}

shinyApp(ui, server)

This leads to waiter first showing the spinner on the first module, then the second (when the first module is done waiting), then the plot from the main ui. I would expect to see the waiter on all reactive elements from the start. Note that all spinners disappear when the last element is rendered.

image

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

No branches or pull requests

1 participant