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

Waitress with Shiny modules #151

Open
fricour opened this issue May 8, 2024 · 0 comments
Open

Waitress with Shiny modules #151

fricour opened this issue May 8, 2024 · 0 comments

Comments

@fricour
Copy link

fricour commented May 8, 2024

Hi,

Thank you for this great package that I am currently exploring !

I am not sure whether it's a bug or if I am doing something wrong but I did not find a way to use waitress with shiny modules.

Let's say I am using a simple app like this one (no modules)

library(shiny)
library(waiter)

ui <- fluidPage(
  useWaitress(),
  actionButton("btn", "render"),
  plotOutput("plot", width = 400)
)

server <- function(input, output){

  waitress <- Waitress$new("#btn", theme = "overlay-percent", infinite = TRUE)

  data <- eventReactive(input$btn,{
    
    # start waitress
    waitress$start()

    # do stuff
    Sys.sleep(3)
    tmp <- runif(100)
    
    # hide when done
    waitress$close() 
    
    return(tmp)
  })

  output$plot <- renderPlot({
    hist(data())
  })

}

shinyApp(ui, server)

It works well.

Now, if I am building the same app with modules

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

  tagList(
    useWaitress(),
    actionButton(ns("btn"), "render"),
    plotOutput(ns("plot"), width = 400)
  )
}

mod_server <- function(id){
  moduleServer(id, function(input, output, session) {
    ns <- session$ns

    waitress <- Waitress$new(ns("#btn"), theme = "overlay-percent", infinite = TRUE)

    data <- eventReactive(input$btn,{

      # start waitress
      waitress$start()

      # do stuff
      Sys.sleep(3)
      tmp <- runif(100)

      # hide when done
      waitress$close()

      return(tmp)
    })

    output$plot <- renderPlot({
      hist(data())
    })

  })
}

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

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

shinyApp(ui = ui, server = server)

The waitress does not appear in that case. I have tried with ns("#btn") and ns("btn") but without success. I feel like something is messing with the selector (for the javascript behind) and that it is lost somewhere with the modular approach.

Any thoughts? Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant