JohnCoene / waiter

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

Cannot change value of locked binding for 'set_loader' #113

Closed shahronak47 closed 2 years ago

shahronak47 commented 2 years ago

I am trying to run the example from the help page for hostess but it is returning me an error.

library(shiny)
library(waiter)

# diagonal line
path <- "M10 10L90 30"

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

server <- function(input, output) {

  dataset <- reactive({
    input$draw

    hostess <- Hostess$new(min = 0, max = 10)
    hostess$set_loader <- hostess_loader(
      progress_type = "stroke",
      stroke_color = hostess_stripe()
    )
    waiter <- Waiter$new(
      "plot", 
      hostess$loader()
    )

    waiter$show()

    for(i in 1:10){
      Sys.sleep(.2)
      hostess$inc(1)
    }

    runif(100)

  })

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

}

shinyApp(ui, server)

This is the error.

Warning: Error in <-: cannot change value of locked binding for 'set_loader'

This is my sessionInfo() -

R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] waiter_0.2.5 shiny_1.7.1 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7       digest_0.6.29    later_1.3.0      mime_0.12        R6_2.5.1         jsonlite_1.7.2   lifecycle_1.0.1 
 [8] xtable_1.8-4     magrittr_2.0.1   cachem_1.0.6     rlang_0.4.12     cli_3.1.0        promises_1.2.0.1 jquerylib_0.1.4 
[15] bslib_0.3.1      ellipsis_0.3.2   tools_4.1.0      rsconnect_0.8.18 httpuv_1.6.5     fastmap_1.1.0    compiler_4.1.0  
[22] htmltools_0.5.2  sass_0.4.0      
JohnCoene commented 2 years ago

It looks like you are looking at a very outdated documentation. May I ask where you saw this?

See the correct code the latest version below.

library(shiny)
library(waiter)

# diagonal line
path <- "M10 10L90 30"

ui <- fluidPage(
  useWaiter(),
  useHostess(),
  actionButton("draw", "redraw"),
  plotOutput("plot")
)

server <- function(input, output) {

  dataset <- reactive({
    input$draw

    hostess <- Hostess$new(min = 0, max = 10)
    hostess$set_loader(
      hostess_loader(
      progress_type = "stroke",
      stroke_color = hostess_stripe()
      )
    )
    waiter <- Waiter$new(
      "plot", 
      html = hostess$get_loader()
    )

    waiter$show()

    for(i in 1:10){
      Sys.sleep(.2)
      hostess$inc(1)
    }

    runif(100)

  })

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

}

shinyApp(ui, server)
shahronak47 commented 2 years ago

@JohnCoene I find the example under ?waiter::hostessLoader .

JohnCoene commented 2 years ago

Thank you.