Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Created May 21, 2014 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpsievert/27c92ee1061e316a80f0 to your computer and use it in GitHub Desktop.
Save cpsievert/27c92ee1061e316a80f0 to your computer and use it in GitHub Desktop.
library(devtools)
install_github("ramnathv/rCharts")
# This will soon have to be install_github("rOpenSci/gistr"); see convo here https://twitter.com/ramnath_vaidya/status/469160178898989056
library(rCharts)
# set your GitHub username and password
options(github.username = "foo", github.password = "bar")
animint2gist <- function(plot.list, out.dir = tempfile(), json.file = "plot.json", open.blocks = interactive()){
gg2animint(plot.list, out.dir, json.file, open.browser = FALSE)
# use a flat file structure!
vendor.path <- file.path(out.dir, "vendor")
vendor.files <- list.files(vendor.path)
vendor.path.files <- file.path(vendor.path, vendor.files)
copied <- file.copy(vendor.path.files, file.path(out.dir, vendor.files))
file.remove(vendor.path.files)
file.remove(vendor.path)
# reflect script path in index.html to reflect the change in file structure
index.file <- file.path(out.dir, "index.html")
html <- readLines(index.file)
html <- gsub("vendor/", "", html)
cat(html, file = index.file, sep = "\n")
gist <- create_gist(file.path(out.dir, list.files(out.dir)), description = "My first animint plot", public = TRUE)
ext <- suppressMessages(post_gist(gist))
blocks_url <- paste("http://bl.ocks.org", getOption("github.username"), ext, sep = "/")
if (open.blocks) browseURL(blocks_url)
}
library(animint)
iris$id <- 1:nrow(iris)
viz <-
list(petal=ggplot()+
geom_point(aes(Petal.Width, Petal.Length, fill=Species,
clickSelects=id),
data=iris),
sepal=ggplot()+
geom_point(aes(Sepal.Width, Sepal.Length, fill=Species,
clickSelects=id),
data=iris))
animint2gist(viz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment