0

How can I distribute R visualizations to other users that don't have R?

I have a created a Sankey diagram in R based on the following code (Link), which works great:

library(networkD3)
library(jsonlite)
library(magrittr)
energy <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json" %>% 
  fromJSON
sankeyNetwork(Links = energy$links, 
          Nodes = energy$nodes, 
          Source = "source",
          Target = "target", 
          Value = "value", 
          NodeID = "name",
          units = "TWh", 
          fontSize = 12, 
          nodeWidth = 30)

But, how can I pass this diagram to other users? I was thinking maybe to render it in a web page, but I don't know how.

Any ideas?

Thanks

Community
  • 1
  • 1
Selrac
  • 2,203
  • 9
  • 41
  • 84
  • 1
    How about good old images? If you want to also include some text, you can try `rmarkdown` and `knitr`. – AlexR Jan 22 '17 at 08:28
  • The images are missing the interaction available in the chart. If you run the code you will see that when you hover in the chart in R you get a tool-tip and the link between nodes get highlighted. You miss that with just an image. – Selrac Jan 22 '17 at 08:39
  • What's about [shiny](https://shiny.rstudio.com/)? – Roman Jan 23 '17 at 09:02
  • I can not figure out how to use shiny to add this type of diagram – Selrac Jan 23 '17 at 18:51

1 Answers1

1

If you are using RStudio then you can compile an HTML report using GUI: enter image description here This will quickly create an HTML file with your code and the interactive plot.

Alternatively, you could also knit an R markdown document with your code. More info here. Please bear in mind that only HTML version will be interactive.

epo3
  • 2,991
  • 2
  • 33
  • 60
  • The button you mention doesn't really compile the HTML. Maybe I'm doing something wrong. I tried: rmarkdown::render('C:/path/r_sankeyDiagram.R') but I'm getting an error message: there is no package called 'jsonlite' – Selrac Jan 23 '17 at 17:53
  • this means that you don't have the jsonlite package installed. just run `install.packages("jsonlite")` before compiling the report. – epo3 Jan 24 '17 at 09:38