rstudio / promises

A promise library for R
https://rstudio.github.io/promises
Other
198 stars 19 forks source link

Async process doesn't block shiny app within "user session" #35

Open oganm opened 5 years ago

oganm commented 5 years ago

I was experimenting promises and as I understand, as pointed out in issue #23, an async process running for the same user is supposed to block execution of all other intra-session activities. However this doesn't seem to be a universal principle.

In the example app below, I have an artificially drawn out plotting operation and some other elements to see how they interact. One of these elements is a downloadButton/downloadHandler pair. While the async operation is running, it is still possible to press the downloadButton and get an input, which was unexpected for me. In fact before the first 10 seconds, the downloadButton still works but pretends downloadHandler isn't there and downloads the whole page. After the first 10 seconds, downloadButton will download the intended file immediately even if an async process is running. My questions are:

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

server = function(input, output) {
    # slow async plot
    output$slow_plot <- renderPlot({
        input$slow_plot_button
        future({
            print('I am slow')
            Sys.sleep(10)
            runif(20)
        }) %...>% plot(.)

    })
    # fast normal plot
    output$fast_plot = renderPlot({
        print('I am fast')
        input$fast_plot_button
        plot(runif(20))
    })
    # something that has no UI output
    observeEvent(input$non_ui_update,{
        print('Button press yay!')
    })
    # trigger happy downloadHandler
    output$download = downloadHandler('file',
                    content = function(file){
                        cat('is a file',file = file)
                    })
}

ui = fluidPage(
    titlePanel("Async test"),
    sidebarLayout(
        sidebarPanel(
            actionButton('slow_plot_button','slow plot button'),
            actionButton('fast_plot_button','fast plot button'),
            actionButton('non_ui_update','non ui update'),
            downloadButton('download','download')
        ),
        mainPanel(
            plotOutput("slow_plot"),
            plotOutput("fast_plot")
        )
    )
)

shinyApp(ui,server)
king-of-poppk commented 1 year ago

That's probably more a Shiny issue than a promises issue.

king-of-poppk commented 1 year ago

Somewhat related: https://github.com/rstudio/promises/issues/23#issuecomment-1299008273