在 Markdown 中嵌入 rChart [英] embed rChart in Markdown
问题描述
我正在尝试在 Markdown 文档中嵌入 NVD3 图表.我在带有 RStudio 0.98.932、R 3.1.0、rCharts 0.4.2 的 Ubuntu64 系统上,浏览器是 Chrome.
I am trying to embed a NVD3 chart in a Markdown document. I am on a Ubuntu64 system with RStudio 0.98.932, R 3.1.0, rCharts 0.4.2, the browser is Chrome.
来自此链接的说明/代码:
The instructions/code from this link:
```{r}
library(rCharts)
library(knitr)
opts_chunk$set(comment = NA, results = "asis", comment = NA, tidy = F)
hair_eye_male = subset(as.data.frame(HairEyeColor), Sex == "Male")
n1 <- nPlot(Freq ~ Hair, group = 'Eye',
data = hair_eye_male, type = 'multiBarChart'
)
n1$set(width = 600)
# n1$show('iframesrc', cdn = TRUE) # option 1
# n1$show('inline', include_assets = TRUE, cdn = TRUE) # option 2
```
选项 [n1$show] 都不起作用,我只是在浏览器中获取代码.有没有另一种方法可以在 Markdown 中包含 NVD3 文档?
Neither of the options [n1$show] work, I just get code in a browser. Is there another way of including NVD3 documents in Markdown?
推荐答案
此代码对我有用.我正在使用 ubuntu64 和您提到的相同配置.
This code is working for me. I am using ubuntu64 and same config you mentioned.
```{r, echo=FALSE,results='asis',comment=NA}
library(rCharts)
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male")
n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarChart")
n1$show('iframesrc',cdn=TRUE)
```
注意:您必须在chunk options中写入results='asis'和comment = NA,而不是像您那样使用opts_chunk$set
在您的代码块以及您粘贴到 copy.com 的内容中.
Note : you must write results='asis' and comment = NA in chunk options and not use opts_chunk$set
as you have in your code block and what you pasted to copy.com.
这篇关于在 Markdown 中嵌入 rChart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!