【问题标题】:Shiny downloadHandler doesn't save PNG files闪亮的downloadHandler不保存PNG文件
【发布时间】:2014-08-24 19:17:47
【问题描述】:

我有我的下载功能,一切正常,当另存为屏幕出现时,我指定的文件名出现。当我点击保存时,窗口关闭,但没有文件被保存...

相同的情节在应用程序中运行良好,唯一的问题是我似乎无法将其保存到 PNG 文件中。

我在笔记本电脑上运行闪耀应用程序并使用 RStudio。

这是我的一些代码摘录。

ui.R

downloadButton('downloadSMemPlot', 'Download Graph')


server.R

'#draw membersip plot
s.MemPlotInput <- reactive({

'#some code to get data

s.MemPlot <- ggplot() + 
 geom_density(aes(x=Age, fill = Years), data=s.ben, alpha = 0.5) + 
 ggtitle("Density of beneficiary ages") + 
 theme_igray() + 
 theme(plot.title = element_text(lineheight=.8, face="bold")) +
 xlab("Age in full years") + ylab("Density")+
 scale_fill_hue()
})

output$s.memplot <- renderPlot({
  print(s.MemPlotInput())
})

'#download membership plot  
output$downloadSMemPlot <- downloadHandler(
  filename = "MembershipPlot.png",
  content = function(file) {
    png(file, type='cairo')
    print(s.MemPlotInput())
    dev.off()
  },
  contentType = 'application/png'
)

【问题讨论】:

    标签: r save shiny


    【解决方案1】:

    你想要

    contentType = 'image/png'
    

    不是

    contentType = 'application/png'
    

    虽然我不认为这是问题所在。您是在 RStudio 的预览窗格中还是在外部浏览器中运行它?使用预览窗格时,我在下载时遇到了同样的问题,但在我的浏览器上运行良好。

    【讨论】:

    • 我遇到了同样的问题,但无法弄清楚问题所在。 PDF 工作,但没有其他图像类型。按照 Chris 的建议,在浏览器中打开而不是 RStudio 预览面板,解决了问题
    猜你喜欢
    • 2015-10-22
    • 2014-11-17
    • 2018-08-02
    • 1970-01-01
    • 2020-04-20
    • 2017-07-06
    • 2021-12-22
    • 1970-01-01
    • 2020-09-21
    相关资源
    最近更新 更多