2

I want to be able to export the charts generated in my shiny application using rCharts to Image and PDF formats. Is there any provision in the rCharts library for that?

I have earlier used ggvis, It gives an option for resizing the chart in the browser and also an option to download the chart in HTML or PNG format. Anything similar to that?

Edit 1:

I'm using nvd3 and polyCharts as my charting libraries currently.

Megh Vidani
  • 635
  • 1
  • 7
  • 22

2 Answers2

2

To download as image or pdf you can use a$exporting(enabled = T), assuming your chart is called a.

library(rCharts)
a <- hPlot(Pulse ~ Height, data = MASS::survey, type = "scatter", group = "Exer")
a$exporting(enabled = T)
a

enter image description here

Pork Chop
  • 28,528
  • 5
  • 63
  • 77
  • Thanks! does it work for `NVD3` and `polyCharts` too? Or it's only for `highCharts` ? – Megh Vidani Apr 08 '16 at 07:34
  • I tried this for `NVD3` and `polyCharts` but it is not working. :( It says: ‘exporting’ is not a valid field or method name for reference class “Polycharts"! and same for NVD3... Do you know any workaround for this? – Megh Vidani Apr 08 '16 at 08:54
  • I believe this is only a highcharts feature. Alternatively, you could issue a call to the `htmlwidgets::saveWidget()` function – Paul Govan Apr 08 '16 at 19:47
  • @PaulGovan Where to put that call? inside renderChart2 ? – Megh Vidani Apr 12 '16 at 12:28
1

To follow up on my comment above, I was a bit too quick to respond, as the htmlwidget::saveWidget() function is meant for widgets developed under the htmlwidgets.org framework. However, rCharts has a similar function:

library(rCharts)

a <- nPlot(Pulse ~ Height, data = MASS::survey, type = "scatterChart", group = "Exer")
a$save("demo.html", standalone=TRUE)

Where 'demo.html' is standalone html file. Creating a png is as simple as taking a screenshot. Note that you can also call this function in a shiny app.

Paul Govan
  • 673
  • 6
  • 20
  • Hi Paul! I'm aware about the save function. I didn't understand the "taking screenshot" part of your answer. How does taking screenshot solve the problem? And what about pdf? – Megh Vidani Apr 13 '16 at 10:07