JohnCoene / waiter

🕰️ Loading screens for Shiny
https://waiter.john-coene.com/
Other
496 stars 25 forks source link

Properly displaying waiter before output is rendered #92

Closed mhoban closed 3 years ago

mhoban commented 3 years ago

I'm not sure if it's more appropriate to ask this here or in the repo for DT, but I'll start here. I have a dataset that takes a little while to load that's ultimately being displayed with DT::renderDataTable. The issue I run into is that the first time the data loads (i.e. when it takes the most time and thus I'd most want to display the spinner), the datatable component is not yet rendered and thus there's nowhere for the waiter to show itself. This seems to be an issue with renderTable as well. Is there some way around this, either by pre-rendering the component, specifying its dimensions in CSS, or something else?

In this example, the spinner only shows after the first time the data is loaded. Is it possible to make it show the first time too?

library(shiny)
library(waiter)
library(DT)

ui <- fluidPage(
  use_waiter(),  

  sidebarLayout(
    sidebarPanel(
      actionButton("reload","Reload data")
    ),

    mainPanel(
      DTOutput("dt")
    )
  )
)

server <- function(input, output) {
  w <- Waiter$new("dt")

  # ignoreNULL makes this load the first time without clicking
  # then reload every time the button is clicked
  csv <- eventReactive(input$reload,{
    showNotification("Loading data",type="message",duration = 3)

    # in this example, the spinner only shows AFTER the first time the data is loaded
    w$show()
    on.exit(w$hide())
    Sys.sleep(3)
    faithful
  },ignoreNULL = FALSE)

  output$dt <- renderDT({
    csv()
  })
}

# Run the application 
shinyApp(ui = ui, server = server)
mhoban commented 3 years ago

I think it turns out I was just entering the height incorrectly. I figured this out.