History: Profile_r_test9_rcharts_512paths
Source of version: 1 (current)
Copy to clipboard
Testing a nice interactive graph created with rCharts & d3, with data from x512paths: NY Times 512 Paths to the White House. Recreated in R with rCharts and slidify. For more information, see: * http://timelyportfolio.blogspot.com.es/2013/04/d3-r-with-rcharts-and-slidify.html * http://timelyportfolio.github.io/rCharts_512paths/ {RR(echo="1" cacheby="pagename")} # Testing rCharts & d3, from http://timelyportfolio.blogspot.com.es/2013/04/d3-r-with-rcharts-and-slidify.html # Set a mirror, in case the required packages have dependencies, and those dependencies do not indicate which mirror to install the package from. r <- getOption("repos") r["CRAN"] <- "http://ftp.heanet.ie/mirrors/cran.r-project.org/" options(repos=r) # Update packages first update.packages(ask = FALSE, repos = 'http://cran.rstudio.org') # if you have not installed slidify, slidifyLibraries, or rCharts if(!require(devtools)){ install.packages("devtools", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") } require('devtools', quietly = TRUE ) if(!require(slidify)){ install_github('slidify', 'ramnathv', ref = 'dev') } require(slidify, quietly = TRUE) if(!require(rCharts)){ install_github('rCharts', 'ramnathv') } if(!require(codetools)){ install.packages("codetools", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") } require(codetools, quietly = TRUE ) if(!require(slidifyLibraries)){ install_github('slidifyLibraries', 'ramnathv', ref = 'dev') } # optional # get data from downloaded NYT tsv and inject in through params # download repo and unzip to Downloads folder if(!require(downloader)){ install.packages("downloader", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") } require(downloader, quietly = TRUE ) download( 'https://github.com/timelyportfolio/rCharts_512paths/archive/gh-pages.zip', 'rCharts_512paths.zip' ) # If you are in multitiki, jump 3 directories for the directory to save the files unzip('rCharts_512paths.zip', exdir = '../../../public/') # Alternatively, jump just two. #unzip('rCharts_512paths.zip', exdir = '../../public/') # Set the working directory # If you are in multitiki, jump 3 directories setwd('../../../public/rCharts_512paths-gh-pages') # Alternatively, jump just two. #setwd('../../public/rCharts_512paths-gh-pages') # plot the data require(rCharts, quietly = TRUE ) data <- read.delim(file = "data/states.tsv") p1 <- rCharts$new() getwd(); p1$field("lib", "libraries/widgets/x512paths") p1$set(data = toJSONArray(data), dom = NULL) # We have to fix some relative path which seems to be wrong for its equivalent absolute path p1$LIB[2] <- paste("http://{{domain}}/temp/public/rCharts_512paths-gh-pages", "/", p1$lib, sep="") p1$templates$script <- paste(p1$LIB[2], p1$templates$script, sep="") # Here we don't create the chart on the fly with a random page name in an uncontroled directory server side, but instead, we save the p1 object as html page ni a defined-by-us path & filename. # Path, by default, is the working directory #p1 p1$save('mychart.html') {RR} Now we show the chart in this wiki page through an iframe: {CODE()} {iframe name="myChart" width="1000" height="1200" align="middle" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" src="temp/public/rCharts_512paths-gh-pages/mychart.html"} {CODE} {iframe name="myChart" width="1000" height="1200" align="middle" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" src="temp/public/rCharts_512paths-gh-pages/mychart.html"}