waiter icon indicating copy to clipboard operation
waiter copied to clipboard

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

Open DavZim opened this issue 2 years ago • 0 comments

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

DavZim avatar Feb 02 '23 15:02 DavZim