JohnCoene / waiter

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

Events #62

Closed JohnCoene closed 4 years ago

JohnCoene commented 4 years ago

Retrieve when waiter is shown or hidden as input.

JohnCoene commented 4 years ago

Can now be done, see docs

library(shiny)
library(waiter)

ui <- fluidPage(
  use_waiter(),
  actionButton("draw", "draw plot"),
  plotOutput("plot")
)

server <- function(input, output){

  # sets: 
  # input$plot_waiter_shown
  # input$plot_waiter_hidden
  w <- Waiter$new(id = "plot")

  dataset <- reactive({
    input$draw

    w$show()

    on.exit({
      w$hide()
    })

    Sys.sleep(3)  

    runif(100)
  })

  output$plot <- renderPlot(plot(dataset()))

  observeEvent(input$plot_waiter_hidden, {
    print(input$plot_waiter_hidden)
  })

  observeEvent(input$plot_waiter_shown, {
    print(input$plot_waiter_shown)
  })

}

shinyApp(ui, server)