Today, I tried Timeline.js with rCharts.
So what?
I realized Timeline.js and rCharts are very powerful tool.
When you want to use Timeline.js through rCharts, Timelyportfolio is very helpful. I modified the site's code a little.
Let's try and enjoy your timeline!!!
Code
library(plyr)
library(RCurl)
library(rCharts)
s <- "https://docs.google.com/spreadsheet/pub?key=0AroiXQuUrfhwdEFSaDd4UlZmV0YzSUZzZ3JZX01lQ2c&output=csv"
x <- getURL(s, ssl.verifypeer = FALSE, .encoding = "UTF-8")
releaseDates <- read.csv(text = x, as.is = TRUE)
releaseList <- alply(releaseDates, 1, function(x) {
list(startDate = x$Start.Date, headline = x$Headline, text = x$Text, asset = list(media = x$Media))
})
# Create Timeline
m = Timeline$new()
m$main(headline = paste0("A Japanese Star Release History ", format(as.Date("1970-05-01"),
"%Y"), "-", format(as.Date("2009-12-16"), "%Y")), type = "default", text = "Akira Nishikino is a Japanese star. Every Japanese knows him, but worlds don't know.<br>That's too bad.",
startDate = format(as.Date("1948-12-14"), "%Y,%m,%d"), asset = list(media = "http://ja.wikipedia.org/wiki/%E9%8C%A6%E9%87%8E%E6%97%A6"))
names(releaseList) <- NULL
m$event(releaseList)
m$save("140303.html")
# Modify JS Path
x <- paste(readLines("140303.html", 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 = "140303.html")
No comments:
Post a Comment