shiny下载一个excel文件

我有一个shiny服务器上设置一个Linux实例我有一个文件夹称为模板有一个Excel文件模板用户去网页,并按下载button,理论上他们应该能够下载模板,无论他们喜欢他们的本地机器。

我看到后Shiny下载文件的代码不工作

当我尝试运行它,我得到一个文件保存到我的Windows笔记本电脑上的my downloads ,它被称为不是名称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) } )}) 

您正在使用paste(input$filenames, sep='')但是没有在UI部分中定义的input$文件名。 它应该工作,如果你用"Template.xlsm"replace该行