RMarkdown 和 RCharts [英] RMarkdown and RCharts

查看:63
本文介绍了RMarkdown 和 RCharts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行这个 RMarkdown 代码时:

When I run this RMarkdown code:

---
title: "test"
output: html_document
---

```{r cache=FALSE}
library(rCharts)
library(knitr)
opts_chunk$set(comment = NA, results = "asis", comment = NA, tidy = F)

hair_eye = as.data.frame(HairEyeColor)
p2 <- nPlot(Freq ~ Hair, group = 'Eye', data = subset(hair_eye, Sex == "Female"), type = 'multiBarChart')
p2$chart(color = c('brown', 'blue', '#594c26', 'green'))
p2$show('inline', include_assets = TRUE, cdn = TRUE)
```

我明白了:http://rpubs.com/rajesh06/test_Rmd

我还尝试了self-contined: no"选项,更改为:

I also tried the "self-contined: no" option by changing to this:

output: 
  html_document:
    self-contained: no

但这似乎没有帮助.

有什么想法吗?

推荐答案

在我的工作中,我有一台 Mac 并且 $show() 工作正常.我在家里的 PC 上尝试了一些代码,但由于某种原因 $show() 不起作用.但是,有一个简单的方法可以使用 $save() 函数解决这个问题:

In my work I have a Mac and $show() works properly. I tried some of the code at my home's PC and for some reason $show() did not work. However, there is an easy way around to solve this issue using the $save() function:

---
title: "test"
output: html_document
---

```{r cache=FALSE}
library(rCharts)
library(knitr)
opts_chunk$set(comment = NA, results = "asis", comment = NA, tidy = F)

hair_eye = as.data.frame(HairEyeColor)
p2 <- nPlot(Freq ~ Hair, group = 'Eye', data = subset(hair_eye, Sex == "Female"), type = 'multiBarChart')
p2$chart(color = c('brown', 'blue', '#594c26', 'green'))
p2$save("p2.html", standalone = TRUE)
```


<iframe src="p2.html" align="center" width="900" height="600" frameBorder="0"></iframe>

你可以从这里找到我得到这个解决方案的讨论:https://github.com/ramnathv/rCharts/issues/373

You can find the discussion I got this solution from here: https://github.com/ramnathv/rCharts/issues/373

我建议您使用 $save() 函数,因为它实际上允许在独立的 html 中向 rCharts 添加控件,而 $show() 则没有.

I recommend you to use the $save() function as it actually allows adding controls to the rCharts in standalone html which $show() does not.

这篇关于RMarkdown 和 RCharts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆