Hi there, I have a problem with AsyncProgress when deployed in shinyapps.io.
I can make AsyncProgress work perfectly on my machine but not on shinyapps.io (I am on a paid subscription, so the worker limitation of the free tire is not a problem).
Here is an example of the code:
library(shiny)
library(bslib)
library(bsicons)
library(promises)
library(future)
library(ipc)
plan(multisession)
# Define UI for application that draws a histogram
ui <- page_navbar(
theme = bs_theme(version = 5,
bootswatch = "minty"),
nav_spacer(),
nav_panel(
title = "Home",
icon = bs_icon("house"),
tags$p('Push Putton'),
actionButton("btn1", "with promise"),
actionButton("btn2", "without promise"),
),
nav_panel(
title = "Empty page",
icon = bs_icon("database"),
tags$p('Empty page')
),
title = "Trial"
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
observeEvent(input$btn1, {
progress = AsyncProgress$new(session,
min = 1,
max = 10)
#progress$set(message = "In execution ...", value = 0)
future_promise({
for (x in 1:10) {
Sys.sleep(1)
progress$set(message = "In execution ...", value = x)
print(x)
}
progress$close()
})
})
observeEvent(input$btn2, {
progress = Progress$new(session = getDefaultReactiveDomain(),
min = 1,
max = 10,
style = getShinyOption("progress.style", default = "notification"))
on.exit(progress$close())
progress$set(message = "In execution ...", value = 0)
for (x in 1:10) {
Sys.sleep(1)
progress$set(message = "In execution row ...", value = x)
print(x)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
The interesting thing is that if I set plan(multisession(workers = 3)), the progress bar actually works, but if multiple users call the function at the same time, the app crashes, and I get the following error in the logs:
Warning: Error in : MultisessionFuture () failed to call grmall() on cluster RichSOCKnode #1 (PID 415 on localhost ‘localhost’). The reason reported was ‘error writing to connection’. Post-mortem diagnostic: A process with this PID exists, which suggests that the localhost worker is still alive.
So, it seems, but please correct me if I am wrong, that Shinyapps.io does not pass the correct PID to AsyncProgress. If the number of workers is set, it forces the PID but it crashes if the local worker already exists. Is there a workaround for this problem? Any help would be more than appreciated.
Thank you so much