【问题标题】:rChart in R Markdown doesn't renderR Markdown中的rChart不呈现
【发布时间】:2015-01-23 23:14:26
【问题描述】:

当我将 R Markdown 文档编织成 html 时,我在渲染使用“nPlot”制作的 rChart 时遇到问题。

我遵循了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)

【问题讨论】:

    标签: r nvd3.js r-markdown rcharts


    【解决方案1】:

    明白了。

    看到这个答案:Ramnath layin' it down

    (当我们意识到我们只是在看过时的教程/演练时,胸中的满足感很快就消退了......)

    最后一行应该是

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

    我认为那里的大多数教程都使用旧版本或其他东西。但以上对我有用,所以试一试。

    然后编织,然后你就可以开始了。还要确保你的 rCharts 库是最新的

    install_github("ramnathv/rCharts")
    

    【讨论】:

    • 恐怕这些建议都没有成功
    • 呃……对不起。我遇到了和你一样的问题。上面的代码似乎与我能够挖掘的每个示例/演练相同,但它只是显示为空白。如果重要的话,我在使用 chrome 的 windows 盒子上。
    • @user3334472,见上文。我们正在查看过期的教程。
    • 超级。如果有人偶然发现此页面,请注意:由于cdn,我在您的代码中遇到了 css 错误。我的工作代码很简单:m1$print('iframesrc', include_assets = TRUE)
    【解决方案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 正在寻找一个公共文件,但找不到它。
    • 每个图表都需要一个唯一的名称,否则它们将覆盖或叠加在一起。
    • 您可以在选项块中更新图表的高度和宽度
    • 我有 R 3.1.2, rCharts_0.4.5, rmarkdown_0.7

    【讨论】:

      【解决方案3】:

      您可以将 rChart 图保存为 html,然后使用 shiny::includeHTML("plot.html") 将其包含到 RMarkdown 文档中。这对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-21
        • 2019-11-14
        相关资源
        最近更新 更多