values examples dyseries dyoptions dygraph change candlestick r shiny dygraphs

examples - Brillante: exportar diagrama dinámico a la imagen?



dyseries r (1)

Esta pregunta es bastante antigua, pero tal vez esta respuesta aún pueda ser útil para usted o para otra persona. Esta pregunta está directamente relacionada con esta pregunta: ¿Cómo guardar el folleto en el mapa R como archivo png o jpg? . Estaba teniendo el mismo problema que tú y aquí está cómo lo resolví para mi caso:

Deberá instalar los paquetes "htmlwidgets" y "webshot". Entonces,

library(htmlwidgets) library(webshot)

También necesitarás instalar PhantomJS. Entonces,

Guarde su trazado como un objeto separado en el lado del servidor con una llamada de función genérica. Tendrá que crear su variable VariableVariables en un entorno reactivo separado, por lo que ahora se tratará como una función:

dyplot <- function(){ dygraph(ReshapedVariables(), main=Title) %>% labelsDiv="VariablePlotLegend", show="always") %>% dyLegend(labelsSeparateLines = FALSE, labelsDiv="VariablePlotLegend",show="always") %>% dyOptions(strokeWidth=2, axisLineColor=GRAPH_BLUE, axisLabelColor=GRAPH_BLUE, gridLineWidth=0.1)}

y luego la descarga:

output$downloadData <- downloadHandler( filename = function () {paste(input$group,''-top6_plot'', Sys.Date(),''.png'',sep='''') }, content = function(file) { saveWidget(dyplot(), "temp.html", selfcontained = FALSE) webshot("temp.html", file = file) } )

Estoy usando brillos y me gustaría crear un botón de descarga que almacene la trama actual como imagen. esto funciona:

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'' )

Pero estoy usando dygraphs para diagramas dyanmic y esto crea una imagen blanca vacía:

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'' )

Pero el código de la trama para dygraphs funciona en general ... porque en la aplicación web brillante muestra la trama correctamente.