首页 > 解决方案 > downloadHandler 唯一地忽略同一用户正在进行的异步进程

问题描述

我正在试验承诺,据我所知,正如本期所指出的,为同一用户运行的异步进程应该阻止所有其他会话内活动的执行。然而,这似乎不是一个普遍的原则。

在下面的示例应用程序中,我有一个人为绘制的绘图操作和一些其他元素,以查看它们如何交互。其中一个元素是downloadButton/downloadHandler对。在异步操作运行时,仍然可以按downloadButton并获得输出,这对我来说是出乎意料的。我的问题是:


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)

编辑:删除了有关 downloadButton 下载整个页面的附加信息,因为它不是问题的组成部分

标签: rshinyr-future

解决方案


推荐阅读