Can shiny async work in shinyapps.io?

Shiny's async capability (using {promises} and {future}) is really great for allowing multiple users to share one shiny app session. When one user is waiting for a long computation, only that user is blocked while other users are still able to continue to use the app.

I recently tested the following simple app. Locally it works as expected: if I open multiple browser sessions, they don't wait for each other. But when deployed to shinyapps.io, that doesn't seem to work. Can async work in shinyappsio?

library(shiny)
library(promises)
library(future)
plan(multisession)

ui <- fluidPage(
  numericInput("num", "num", 5),
  "Double: ",
  textOutput("text", inline = TRUE)
)

server <- function(input, output, session) {
  output$text <- renderText({
    num <- input$num
    future_promise({
      Sys.sleep(3)
      num * 2
    })
  })
}

shinyApp(ui, server)
1 Like

Hi @daattali ,

I think yes: shiny async work in shinyapps.io?
However, I guess this depends on the plan you subscribed.
You probably need a plan with Performance Boost to achieve this

I did some testings and only 1 worker is available on free and starter

see here
library(shiny)
library(promises)
library(future)
plan(multisession(workers = 5))

ui <- fluidPage(
  tags$p("available cores =", future::availableCores(), inline = TRUE),
  "free workers =",   textOutput("free_wkr", inline = TRUE),

  verbatimTextOutput("cur_plan"),
  numericInput("num", "num", 5),
  "Double: ",
  textOutput("text", inline = TRUE),
  actionButton("newplot","New Plot"),
  plotOutput("plot")
)

server <- function(input, output, session) {
  output$plot <- renderPlot({
    input$newplot
    k <- sample.int(1:10, n = 1)
    hist(rnorm(500, mean = k, sd = 1/k), breaks = 128)
  })
  output$free_wkr <- renderText({
    input$newplot
    num <- input$num
    future::nbrOfFreeWorkers()
  })
  output$cur_plan <- renderPrint({
    future::plan()
  })
  output$text <- renderText({
    num <- input$num
    future_promise({
      Sys.sleep(5)
      num * 2
    })
  })
}
# you should be able to trigger new plots while text is being computing in concurrent session
# unless number of availble free workers reach 0
shinyApp(ui, server)
1 Like

Please see this:

With the Basic plan and above, you can configure how many workers you would like to use and when they should be added.

1 Like

Do you happen to have a Basic or above plan so that you can confirm this via teseting?

Unfortunately not from my side :frowning_face:

No sorry - same here.

It looks like my code does indeed work on shinyappsio as well, I just needed to specify number of workers in plan(). For example plan(multisession, workers = 4). Locally it seems that gets set to a number higher than 1 automatically

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.