JohnCoene / waiter

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

Waitress not showing up when plot is being render #155

Closed anusurendra closed 2 hours ago

anusurendra commented 3 hours ago

Hi, I am not able to able to render the watiress on my histogram plot. Below is the code:

library(shiny)
library(waiter)

ui <- navbarPage(
  "Waitress on nav",
  tabPanel(
    "home",
    p(
      em("Visualization")
    ), br(),
    p(
      "Histogram of normalized raw data"
    ),
      tags$table(
            width = "100%", border = "0",
            tags$tr(
              tags$td(span(plotOutput("hist1"))), tags$td(span(plotOutput("hist2")))
            ),
          ), br(), br()
  )
)

server <- function(input, output){

  # now waitress ranges from 0 to 100
  waitress <- Waitress$new("hist1", theme = "overlay", min = 0, max = 10)

  output$hist1 <- renderPlot({

    for(i in 1:10){
      waitress$inc(1) # increase by 10%
      Sys.sleep(.5)
    }

    hist(runif(100))
    waitress$close() # hide when done
  })

}

shinyApp(ui, server)
JohnCoene commented 2 hours ago

You need (see doc).

  1. Include the dependency (useWaitress)
  2. Pass a valid selector (#hist1)
library(shiny)

ui <- navbarPage(
  "Waitress on nav",
  tabPanel(
    "home",
    useWaitress(),
    p(
      em("Visualization")
    ), br(),
    p(
      "Histogram of normalized raw data"
    ),
    actionButton("render", "Render"),
    plotOutput("hist1")
  )
)

server <- function(input, output){

  # now waitress ranges from 0 to 100
  waitress <- Waitress$new("#hist1", theme = "overlay", min = 0, max = 10)

  output$hist1 <- renderPlot({
    input$render
    on.exit(
      waitress$close() # hide when done
    )

    for(i in 1:10){
      waitress$inc(1) # increase by 10%
      Sys.sleep(.5)
    }

    hist(runif(100))
  })

}

shinyApp(ui, server)