Created
May 21, 2014 18:43
-
-
Save cpsievert/27c92ee1061e316a80f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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