Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use waiter_preloader with hostess in a module #108

Closed
Camil88 opened this issue Sep 22, 2021 · 4 comments
Closed

Can't use waiter_preloader with hostess in a module #108

Camil88 opened this issue Sep 22, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@Camil88
Copy link

Camil88 commented Sep 22, 2021

Hi, I would like to add loading bar to the preloader. Loading bar would reflect the progress made in the back end. When everything's ready then they would all disappear. I added for loop to reflect server computations. Unfortunately, I can't see any loading bar under "Loading data..." title. I modularized my app but even without modules it doesn't work. How can I add hostess to waiter in below case and make loading bar reflecting real loading time on server side (because here in example I mimicked server computations using for loop, I don't want that)?

library(shiny)
library(waiter)

moduleServer <- function(id, module) {
   callModule(module, id)
}

mod_ui <- function(id) {
   ns <- NS(id)
 
   tagList(  
   url <- "https://www.freecodecamp.org/news/content/images/size/w2000/2020/04/w-qjCHPZbeXCQ-unsplash.jpg",
   
   use_waiter(),
   use_hostess(),
   
   waiter_preloader(html = h1("Loading data..."), image = url,
   hostess_loader(
      id = "loader",
      preset = "circle",
      text_color = "white",
      class = "label-center",
      center_page = TRUE)
      )
   )
}

# Server #
mod_server <- function(id){
   moduleServer(id, function(input, output, session) {
      ns <- session$ns
      hostess <- Hostess$new(ns("loader"))
     
     # I don't want this loop, bar should load to 100% and disappear when server is ready
      for(i in 1:10){
         Sys.sleep(runif(1) / 2)
         hostess$set(i * 10)
      }
      waiter_hide()
   })

}


# App #
ui <- fluidPage(
      mod_ui("test_ui")
)

server <- function(input, output, session) {
   mod_server("test_ui")
}

shinyApp(ui = ui, server = server)

EDIT: removing html from waiter_preloader makes loading circle visible but I need html conent here as well, why it doesn't work?

@JohnCoene JohnCoene added the bug Something isn't working label Sep 29, 2021
@JohnCoene JohnCoene self-assigned this Sep 29, 2021
@JohnCoene
Copy link
Owner

Apologies, you opened this issue right at the start of a week off. It's definitely a bug, I'll look into it.

@Camil88
Copy link
Author

Camil88 commented Oct 1, 2021

Ok, no problem:) Please let us know once it's fixed, thanks in advance!

JohnCoene added a commit that referenced this issue Oct 3, 2021
JohnCoene added a commit that referenced this issue Oct 3, 2021
@JohnCoene
Copy link
Owner

There was both a bug with the hostess and issues with your markup: the mod_ui is not right.

Reinstall to get the bug fix and use the corrected markup below.

library(shiny)
devtools::load_all()

mod_ui <- function(id) {
  ns <- NS(id)

  url <- "https://www.freecodecamp.org/news/content/images/size/w2000/2020/04/w-qjCHPZbeXCQ-unsplash.jpg"
 
  tagList(  
    useWaiter(),
    useHostess(),
    waiter_preloader(
      html = div(
        h2("Loading data..."),
        hostess_loader(
          id = "loader",
          preset = "circle",
          text_color = "white",
          class = "label-center",
          center_page = TRUE
        )
      ),
      image = url
    )
  )
}

# Server #
mod_server <- function(id){
  moduleServer(id, function(input, output, session) {
    ns <- session$ns
    hostess <- Hostess$new("loader")
    
    # I don't want this loop, bar should load to 100% and disappear when server is ready
    for(i in 1:10){
        Sys.sleep(runif(1) / 2)
        hostess$set(i * 10)
    }
    waiter_hide()
  })

}


# App #
ui <- fluidPage(
  mod_ui("test_ui")
)

server <- function(input, output, session) {
  mod_server("test_ui")
}

shinyApp(ui = ui, server = server)

Feel free to reopen if this does not fix the issue!

@Camil88
Copy link
Author

Camil88 commented Oct 4, 2021

Thank you, it works fine ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants