无法使用Shiny downloadHandler下载png文件,请改为获取“down.html”

问题描述 投票:0回答:1

我是 Shiny 的新手,正在尝试 downloadHandler。我写了一些简单的代码来下载 png 文件,但它不起作用。当我单击下载按钮时,它显示正在下载“down.html”。任何想法都非常感激!

这是我尝试过的代码。

library(shiny)

ui <- fluidPage(
  downloadButton("down","Download .png")
)

server <- function(input, output, session) {
  
  output$down <- downloadHandler(
   filename = "test.png",
    content = function(file) {
      png(file)
      plot(1:5)
      dev.off
    },
   contentType = "image/png")
}

shinyApp(ui, server)
shiny
1个回答
0
投票

在你的内容函数中,你需要调用

dev.off()
(即添加括号),然后它就可以正常工作了。

© www.soinside.com 2019 - 2024. All rights reserved.