【发布时间】:2015-06-17 08:47:31
【问题描述】:
我正在使用闪亮,我想创建一个下载按钮,将当前绘图存储为图像。这行得通:
output$downloadPlot <- downloadHandler(
filename <- function() {
paste(input$group,'-top6_plot', Sys.Date(),'.png',sep='') },
content <- function(file) {
png(file, width = 980, height = 400, units = "px", pointsize = 12,
bg = "white", res = NA)
plot(sin, -pi, 2*pi)
dev.off()},
contentType = 'image/png'
)
但我正在使用 dygraphs 来绘制动态图,这会创建一个空白图像:
output$downloadPlot <- downloadHandler(
filename <- function() {
paste(input$group,'-top6_plot', Sys.Date(),'.png',sep='') },
content <- function(file) {
png(file, width = 980, height = 400, units = "px", pointsize = 12,
bg = "white", res = NA)
ReshapedVariables<-variablesForPlot()
if(input$timeframe == 1){
Title ="Timeframe: 1 Month"
} else if(input$timeframe==2){
Title ="Timeframe: 3 Months"
} else if(input$timeframe==3){
Title ="Timeframe: 6 Months"
} else if(input$timeframe==4){
Title ="Timeframe: Year to date"
} else if(input$timeframe==5){
Title ="Timeframe: 3 Years"
} else if(input$timeframe==6){
Title ="Timeframe: All"
} else {
Title ="Timeframe: Year to date"
}
dygraph(ReshapedVariables, main=Title) %>%
#dyLegend(width = 200, labelsSeparateLines = TRUE, labelsDiv="VariablePlotLegend", show="always") %>%
dyLegend(labelsSeparateLines = FALSE, labelsDiv="VariablePlotLegend", show="always") %>%
dyOptions(strokeWidth=2, axisLineColor=GRAPH_BLUE, axisLabelColor=GRAPH_BLUE, gridLineWidth=0.1)
dev.off()},
contentType = 'image/png'
)
但 dygraphs 的绘图代码通常可以工作...因为在 web 闪亮应用程序中它正确显示了绘图。
【问题讨论】: