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

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

Open
oganm opened this issue Oct 19, 2018 · 2 comments
Open

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

oganm opened this issue Oct 19, 2018 · 2 comments

Comments

@oganm
Copy link

oganm commented Oct 19, 2018

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:

  • Can I stop this?
  • Why is downloadHandler special?
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)
@oganm oganm changed the title Async process doesn't block shiny app within user session Async process doesn't block shiny app within "user session Oct 29, 2018
@oganm oganm changed the title Async process doesn't block shiny app within "user session Async process doesn't block shiny app within "user session" Oct 29, 2018
@king-of-poppk
Copy link

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

@king-of-poppk
Copy link

Somewhat related: #23 (comment)

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

2 participants