2 Knitr/R Markdown/Rstudio issues: Highcharts and Morris.js

前端 未结 1 1233
囚心锁ツ
囚心锁ツ 2020-12-09 23:34

I\'m presently trying to replicate a few different types of rCharts using my own data. The first is a HighCharts graph with the following code:

````{r}
setwd         


        
相关标签:
1条回答
  • 2020-12-10 00:18

    NOTE: This is the same solution I posted in the knitr google group.

    To get rCharts to work with knit2html, you will need to use the print method with the argument include_assets = TRUE. This is because knitr will not add the js and css assets required by an rCharts plot automatically. Here is a minimal working example.

    ## MorrisJS with Knit2HTML
    
    ```{r results = 'asis', comment = NA}
    require(rCharts)
    data(economics, package = 'ggplot2')
    econ <- transform(economics, date = as.character(date))
    m1 <- mPlot(x = 'date', y = c('psavert', 'uempmed'), type = 'Line',
      data = econ)
    m1$set(pointSize = 0, lineWidth = 1)
    m1$print('chart2', include_assets = TRUE)
    ```
    

    Note that you need to use m1$print('chart2', include_assets = TRUE, cdn = TRUE) if you intend to publish your chart on RPubs, for otherwise the JS and CSS assets will be served from your local library.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题