【发布时间】:2019-04-27 22:13:33
【问题描述】:
我有一个闪亮的应用程序,它需要大量时间下载 zip 文件。我正在尝试使用 futures 和 promises 包来管理下载,以便其他用户可以在下载过程中访问该应用程序。
应用如下所示:
library(shiny)
ui <- fluidPage(
downloadButton("Download", "Download")
)
server <- function(input, output){
output$Download <- downloadHandler(
filename = "Downloads.zip",
content = function(file){
withProgress(message = "Writing Files to Disk. Please wait...", {
temp <- setwd(tempdir())
on.exit(setwd(temp))
files <- c("mtcars.csv", "iris.csv")
write.csv(mtcars, "mtcars.csv")
write.csv(iris, "iris.csv")
zip(zipfile = file, files = files)
})
}
)
}
shinyApp(ui, server)
我尝试将write.csv 包装在future 函数中并设置`虽然这不会引发错误,但在下载过程中其他用户无法使用该应用。
library(shiny)
library(promises)
library(future)
plan(multiprocess)
ui <- fluidPage(
downloadButton("Download", "Download")
)
server <- function(input, output){
output$Download <- downloadHandler(
filename = "Downloads.zip",
content = function(file){
withProgress(message = "Writing Files to Disk. Please wait...", {
temp <- setwd(tempdir())
on.exit(setwd(temp))
files <- c("mtcars.csv", "iris.csv")
future(write.csv(mtcars, "mtcars.csv"))
future(write.csv(iris, "iris.csv"))
zip(zipfile = file, files = files)
})
}
)
}
shinyApp(ui, server)
我还尝试将整个 downloadHandler 函数包装在 future 函数中,但出现错误:
.subset2(x, "impl")$defineOutput(name, value, label) 中的错误:
DownloadUnexpected 的 Unexpected MulticoreFuture 输出 下载的 MultiprocessFuture 输出Unexpected Future 的输出 下载下载时出现意外的环境输出
如何异步处理整个downloadHandler?我正在使用闪亮服务器的开源版本。
【问题讨论】:
标签: r asynchronous shiny