【发布时间】: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'
)
【问题讨论】: