Skip to content

Instantly share code, notes, and snippets.

@jeroen
Last active August 29, 2015 14:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroen/d0d03c7e58443f5a4438 to your computer and use it in GitHub Desktop.
Save jeroen/d0d03c7e58443f5a4438 to your computer and use it in GitHub Desktop.
library(V8)
stopifnot(packageVersion("V8") >= "0.5")
# Create V8 context and load viz.js
ct <- new_context("window")
invisible(ct$source('http://mdaines.github.io/viz.js/viz.js'))
# This runs: Viz("digraph { a -> b; }", "svg")
svg <- ct$call("Viz", "digraph { a -> b; }", "svg")
cat(svg)
# View SVG in Rstudio:
tmp <- tempfile(fileext=".svg")
writeLines(svg, tmp)
rstudio::viewer(tmp)
@timelyportfolio
Copy link

Thanks for putting this up. Since DiagrammeR is installed, we could actually just use the local version of viz.js, so system.file(...).

@jeroen
Copy link
Author

jeroen commented Feb 10, 2015

Yes within a package you should preferably ship the js files in your inst dir (if copyright permits) and load them with system.file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment