r - downloadHandler 唯一地忽略同一用户正在进行的异步进程
问题描述
我正在试验承诺,据我所知,正如本期所指出的,为同一用户运行的异步进程应该阻止所有其他会话内活动的执行。然而,这似乎不是一个普遍的原则。
在下面的示例应用程序中,我有一个人为绘制的绘图操作和一些其他元素,以查看它们如何交互。其中一个元素是downloadButton
/downloadHandler
对。在异步操作运行时,仍然可以按downloadButton
并获得输出,这对我来说是出乎意料的。我的问题是:
- 我可以在异步进程运行时停止 downloadHandler 处于活动状态吗?
- 为什么
downloadHandler
特别?
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 下载整个页面的附加信息,因为它不是问题的组成部分
解决方案
推荐阅读
- docker - Docker Hub 上的 Jenkins docker 镜像摘要与本地镜像不匹配
- python - 如何在数据框中检索和存储第二行和第三行元素
- c++ - -Wundef 不对#ifdef 前面的未定义符号发出警告
- python - 根据日期信息重塑熊猫数据框
- mongodb - 无法在 mongodb 中启用分片
- c - 在声明中使用 sizeof
- ios - EPSignature Swift 5.x 问题/每次我想保存我的签名时应用程序崩溃
- c# - 如何交换 2 位数字并找到较大的结果?
- android - 向 Realme 和 Oppo 发送短信
- search - 在图形数据库(neo4j)中搜索用户,其中单个用户可以有多个(相似而不是重复)实例