Example of Using rCharts with knit2html

We first setup the options required for using rCharts with knit2html

require(rCharts)
## Loading required package: rCharts
options(RCHART_WIDTH = 600, RCHART_HEIGHT = 400)
knitr::opts_chunk$set(comment = NA, results = "asis", message = F)
## utility functiont to add required assets
add_lib_assets <- function(lib, cdn = F) {
    assets = get_assets(get_lib(lib), cdn = cdn)
    styles <- lapply(assets$css, function(style) {
        sprintf("<link rel='stylesheet' href=%s>", style)
    })
    scripts <- lapply(assets$jshead, function(script) {
        sprintf("<script type='text/javascript' src=%s></script>", script)
    })
    cat(paste(c(styles, scripts), collapse = "\n"))
}

Let us now test by trying to create a plot using rCharts

add_lib_assets("polycharts", cdn = T)
r1 <- rPlot(mpg ~ wt, color = "gear", data = mtcars, type = "point")
r1$print("chart1")