闪亮的应用程序下载按钮仅响应 HTML

Shiny App Downloads Button Only respond with HTML

我尝试在 Shiny App 中实现下载按钮时遇到问题。每次我 运行 应用程序时,它只会显示一个 HTML 文件而不是实际的内容文件。这是我的服务器和 UI 部分的代码。

library(shiny)
library(reticulate)

shinyServer(function(input,output){

  reticulate::source_python("function.py")
  data_xi <- run_xi(26)

  output$downloadData <- downloadHandler(

    filename = function(){
      paste(Sys.time(), 'site_mtx.xlsx')
    },

    content = function(file){
      write_xlsx(data_xi, file)
    }
  )
})

这是UI:

library(shiny)

shinyUI(fluidPage(
    downloadButton("downloadData", "Download Metrics Reports")
))

我刚刚尝试在我的python文件中使用网状功能,并将处理后的数据框保存到Shiny App,可以下载,非常感谢!

我 运行 从您的代码中提取了一个示例并进行了一些调整(不幸的是我没有您的文件),它通常会下载一个 xlsx 文件。添加 data.frame( run_xi(26)) 如果这不是问题,也许 "writexl" 库可以解决问题。 希望对你有帮助。

library(shiny)
library(reticulate)
library(writexl)


if (interactive()) {

ui <-fluidPage(
    downloadButton("downloadData", "Download Metrics Reports")
)


server <- function(input,output){

data_xi <- data.frame(s = c(1:3),r = c(4:6), x =c(19:21))


    output$downloadData <- downloadHandler(

        filename = function(){
            paste(Sys.time(), 'site_mtx.xlsx')
        },

        content = function(file){
            write_xlsx(data_xi, file)
        }
    )
}

shinyApp(ui, server)

}