闪亮的下载文件不工作 [英] Shiny download file not working

查看:284
本文介绍了闪亮的下载文件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建R Shiny应用程序,其中有一个下拉列表(selectInput)的文档列表和一个下载按钮。所以功能是用户将从列表中选择一个文档,并使用下载按钮下载该文档。

I am creating R Shiny application in which I have a dropdown (selectInput) of documents list and a download button. So functionality is Users will select a document from the list and download that doc using download button.

在UI.R中

  tabItem(tabName = "Downloads",
                selectInput("filenames", "Choose a document to download:",list.files(path="/srv/shiny-server/apps/dsw/files")),
  downloadButton('downloadData', 'Download')),

在Server.R中

        datasetInput <- reactive({
switch(input$filenames,input$filenames)
   })

output$downloadData <- downloadHandler(
filename = function() { 
paste(input$filenames) 
},
content = function(file) {
write.csv(datasetInput(), file)
}
)

这些文件我已经在我的闪亮应用程序的www文件夹中的Linux服务器上放置。

These documents I have placed on Linux server in the www folder of my shiny application.

myapp

--app.R
--files
   -- Doc1.doc
   -- Doc2.csv

当我运行应用程序时,它只会下载空的.csv或.docx文件,而不是服务器上的实际文件。 >

When I run the application, it just downloads empty .csv or .docx file but not the actual file from server.

推荐答案

解决方法如下:

UI.R

 tabItem(tabName = "Downloads",
            selectInput("filenames", "Choose a document to download:",list.files(path="/srv/shiny-server/apps/files")),
 downloadButton('downloadData', 'Download'))

Server.R

output$downloadData <- downloadHandler(
filename = function() {
paste(input$filenames, sep='')
},
content = function(file) {
myfile <- paste0('/srv/shiny-server/apps/files/',input$filenames, collapse = NULL)
  file.copy(myfile, file)
}
)

这篇关于闪亮的下载文件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆