【发布时间】:2016-09-12 11:43:37
【问题描述】:
我在 Linux 实例上设置了 shiny 服务器
我有一个名为 templates 的文件夹,其中有一个 excel 文件模板
用户进入网页并按下下载按钮,理论上他们应该能够在本地机器上的任何地方下载模板。
我已经看到Shiny download file not working帖子中的代码
当我尝试运行它时,我在我的 Windows 笔记本电脑上获得了一个保存到 my downloads 的文件,它被称为 NA 而不是名称 Template.xlsx
我的两个问题是
- 是否可以提示用户本地保存文件的位置
- 是否可以将其默认为
XLSX
伪代码是
ui <- shinyUI(fluidPage(
# Side Panel with Options
fluidRow(
column(4, wellPanel(
id = "leftPanel",
div(
id = "Header",
h3("Options"),
tags$hr()
),
div(
h4("1. Download the empty excel template"),
downloadButton("downloadBtn", "Download Excel Template")
)
)))))
服务器
# Define server logic required
server <- shinyServer(
function(input, output) {
output$downloadBtn <- downloadHandler(
filename = function() {
paste(input$filenames, sep='')
},
content = function(file) {
myfile <- srcpath <- '/home/foo/Save to Database/templates/Template.xlsm'
file.copy(myfile, file)
}
)})
【问题讨论】: