首页 文章

如何在R Shiny应用程序中下载PowerPoint文件?

提问于
浏览
-1

我有一个闪亮的网络应用程序 . 我想创建一个downloadButton,可以在单击时下载PowerPoint文件 . 我需要在downloadHandler函数中放入什么才能从某个文件路径读取PowerPoint文件,然后将该文件下载到按下按钮的用户?

1 回答

  • 2

    您可以使用 file.copy 功能 . 以下是 c:/temp 中文件的基本示例 .

    library(shiny)
    
    ui <- fluidPage( 
      downloadButton("downloadFile", "Download File")
    )
    
    server <- function(input, output) {
    
      fileName <- "test.pptx"
      filePath <- "c:/temp"
    
      output$downloadFile <- downloadHandler(
        filename = function() {
          fileName # default file name use by browser, it could be different
        },
        content = function(file) {
          file.copy(file.path(filePath, fileName), file)
        }
      )
    }
    
    shinyApp(ui = ui , server = server)
    

相关问题