I was experimenting promises and as I understand, as pointed out in this issue, 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 output, which was unexpected for me. My questions are:
- Can I stop downloadHandler from being active while an async process is running?
- 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)
Edit: Removed additional information about downloadButton downloading the whole page at first as it is not an integral part of the question