3

I produce interactive graphs using dygraph. I can view them in the "Viewer" window in R studio and in a browser.

What is the most convenient way to save these plots (es html?)? Can I mail them?

I run R studio 0.98.507 and sessionInfo() gives:

R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Austria.1252  LC_CTYPE=German_Austria.1252    LC_MONETARY=German_Austria.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Austria.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] PerformanceAnalytics_1.1.0 xts_0.9-7                  zoo_1.7-11                 MASS_7.3-33               
[5] cluster_1.15.2             RODBC_1.3-10              

loaded via a namespace (and not attached):
[1] grid_3.1.0      lattice_0.20-29 tools_3.1.0  
Richi W
  • 3,534
  • 4
  • 20
  • 39

2 Answers2

6

htmlwidgets have a saveWidget function which lets you save the full visualization out as a standalone (or composite) HTML file.

As Miha said, you can knit them as well.

If you don't need the interactivity (which is unlikely in the case of dygraphs) you can also use SVG Crowbar 2 to save out the SVG from the displayed visualization in a browser.

With regard to the "knitting", here's a sample R Markdown document with a dygraph in it:

---
title: "dygraphs knit example"
author: "Bob Rudis (@hrbrmstr)"
date: "March 17, 2015"
output: html_document
---

```{r}
library(dygraphs)
dygraph(nhtemp, main = "New Haven Temperatures") %>% 
  dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01"))
```

Knit that in RStudio and it'll generate a self-contained HTML with the visualization.

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • Could you please add more details how I can knit the plot? thanks! – Richi W Mar 17 '15 at 11:58
  • I managed to produce the html file but my brows (Chrome in a company) does not show the chart. It just puts <!–html_preserve–> then blank <!–/html_preserve–> Can I change the security settings so that it can bee displayed? – Richi W Mar 18 '15 at 15:47
  • I _just_ tried it now and had it view in Chrome - http://note.io/1MKys98 - it worked fine. I'll poke at what might be causing the `` issue in a bit. – hrbrmstr Mar 18 '15 at 19:03
1

From the dygraphs for R website:

You can use dygraphs within R Markdown documents just like any other R plotting function. However, rather than a PNG file being included in your document, the JavaScript required to render your dygraph is included.

It means that (from within Rstudio), using knitr and Rmarkdown packages, you can knit a standalone html document that includes dygraphs. You can email the html file if you like.

Miha Trošt
  • 2,002
  • 22
  • 25