rChart in R Markdown doesn't render

对着背影说爱祢 提交于 2019-12-03 03:49:54
colemand77

GOT IT.

see this answer: Ramnath layin' it down

(chest-swelling feeling of satisfaction quickly deflated upon realization we were just looking at outdated tutorials / walkthroughs...)

last line should be

n1$print('iframesrc', cdn =TRUE, include_assets=TRUE)

I think most of the tutorials out there are using an old version or something. But the above works for me, so give it a shot.

then knit, then you're good to go. Also make sure you're rCharts library is up to date

install_github("ramnathv/rCharts")

I'm adding an updated answer here because I struggled for a long time with many outdated tutorials to get this to actually work. Also, the current answer here did not work for me.

This does work...

```{r set-options, echo=FALSE, cache=FALSE}
options(RCHART_WIDTH = 1000, RCHART_HEIGHT = 400)
```

```{r, echo=FALSE, cache=T, results='asis', comment=NA}
p1 <- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type = 'scatterChart')
p1$print('chart1', include_assets=T)
```

```{r, echo=FALSE, cache=T, results='asis', comment=NA}
hair_eye = as.data.frame(HairEyeColor)
p2 <- nPlot(Freq ~ Hair, group = 'Eye', data = subset(hair_eye, Sex == "Female"), type = 'multiBarChart')
p2$print('chart2', include_assets=T)
```

Note:

  • I needed to set results='asis' and comment=NA in the chunk with the chart code, not the options block at the top.
  • cdn=T caused errors for me. R was looking for a public file and could not find it.
  • The charts each need a unique name or they will override or chart on top of each other.
  • You can update the height and width of your charts in the options chunk
  • I have R 3.1.2, rCharts_0.4.5, rmarkdown_0.7

You can save your rChart plot as a html and then include it to the RMarkdown document with shiny::includeHTML("plot.html"). This worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!