March 8, 2014

Making a slideshow with slideshare and rCharts

So What ?

So far, I have introduced the visualization with R packeges.

Today, I will try to make a slideshow with that packages.

So What ?

rCharts is very powerful package, so even I, who have a little knowledge about Javascript, can make such a slideshow for a minutes.

Pretty soon I will add a function to slideshare package which packs procedures from getting data to visualization.

Code

library(slideshare)
library(rCharts)
library(plyr)

# get data
ss <- Slideshare$new(apikey="Your API key",sharedsecret="Your secret")
res <- ss$getSlideshowByTag("tokyor",limit=100)
res$EmbedModified <- gsub('width="427"','width="600"',res$Embed)
releaseList <- alply(res, 1, function(x) {
    list(startDate = format(as.Date(x$Created), "%Y,%m,%d"), 
         headline = x$Title, 
         text = x$EmbedModified,
         asset=list()
         )
})

# Create Timeline
m = Timeline$new()
m$main(headline = "TokyoR",
       type = "default", 
       text = "These are TokyoR slides", 
       startDate = format(as.Date(min(res$Created)), "%Y,%m,%d"), 
       asset = list(media = "http://www.r-project.org/Rlogo.jpg"))
names(releaseList) <- NULL
m$event(releaseList)
tmp <- tempfile()
m$save(tmp)


# Modify JS Path
x <- paste(readLines(tmp, warn = F), collapse = "\n")
x <- gsub("/Library/Frameworks/R.framework/Versions/3.0/Resources/library/rCharts/libraries/timeline/js/storyjs-embed.js", 
    "http://timelyportfolio.github.io/rCharts_timeline_r/compiled/js/storyjs-embed.js", 
    x)
writeLines(x, con = "140308.html")

No comments:

Post a Comment