【发布时间】:2014-11-12 07:21:46
【问题描述】:
我无法让闪亮的downloadHandler 输出 zip 文件:
# server.R
library(shiny)
shinyServer(function(input, output) {
output$downloadData <- downloadHandler(
filename <- function() {
paste("output", "zip", sep=".")
},
content <- function(fname) {
fs <- c()
tmpdir <- tempdir()
setwd(tempdir())
for (i in c(1,2,3,4,5)) {
path <- paste0("sample_", i, ".csv")
fs <- c(fs, path)
write(i*2, path)
}
zip(zipfile=fname, files=fs)
}
)
})
还有简单的ui.R:
shinyUI(fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
downloadButton("downloadData", label = "Download")
),
mainPanel(h6("Sample download", align = "center"))
)
))
我的输出很好,除了错误:
> shiny::runApp('C:/Users/user/AppData/Local/Temp/test')
Listening on http://127.0.0.1:7280
adding: sample_1.csv (stored 0%)
adding: sample_2.csv (stored 0%)
adding: sample_3.csv (stored 0%)
adding: sample_4.csv (stored 0%)
adding: sample_5.csv (stored 0%)
Error opening file: 2
Error reading: 6
并且没有保存对话框来保存存档。但是在temp 文件夹中会显示正确的存档。如何正确分享存档?
【问题讨论】:
-
试试
library(Rcompression)函数zip看看能不能帮到stackoverflow.com/questions/4624360/… -
请注意,在 Windows 上,您需要安装 Rtools,并且它的 bin 目录需要在您的 PATH 环境中,否则 zip 函数只会默默地什么都不做。