我遇到了使用' nPlot'制作rChart的问题。当我将一个R Markdown文档编织成html时。
我按照本question中讨论的解决方案,但没有成功。
这是我的.Rmd代码
```{r, echo=FALSE}
library(knitr)
```
---
title: "Untitled"
author: "Test"
date: "01/23/2015"
output: html_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
# Here is an rChart
```{r, echo=FALSE, results='asis', comment=NA}
library(rCharts)
m2 <- nPlot(speed ~ dist, data = cars, type = "scatterChart")
m2$show('iframesrc', cdn = TRUE)
```
That was an rChart
以下是该代码中html文档的link。我在RStudio中制作并创作了这个,渲染无法在本地机器上显示,也无法在上传到Dropbox时显示。
当我在控制台中运行以下代码并另存为html时,我得到this rendering。
library(rCharts)
m2 <- nPlot(speed ~ dist, data = cars, type = "scatterChart")
m2$save('test3.html', standalone = TRUE)
答案 0 :(得分:5)
GOT IT。
请参阅此答案:Ramnath layin' it down
(胸部肿胀的满足感迅速缩小,实现我们只是看过时的教程/演练...)
最后一行应该是
n1$print('iframesrc', cdn =TRUE, include_assets=TRUE)
我认为大多数教程都使用旧版本或其他东西。但上面对我来说很有用,所以试一试。
然后编织,然后你很高兴去。还要确保你的rCharts库是最新的install_github("ramnathv/rCharts")
答案 1 :(得分:2)
我在这里添加了一个更新的答案,因为我花了很长时间与许多过时的教程进行实际工作。此外,目前的答案对我不起作用。
这确实有用......
```{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)
```
注意:
results='asis'
和comment=NA
,而不是顶部的选项块。cdn=T
给我造成了错误。 R正在寻找一个公共档案,却找不到它。答案 2 :(得分:0)
您可以将rChart图存储为html,然后将其包含在shiny::includeHTML("plot.html")
的RMarkdown文档中。这对我有用。