fat*_*gon 5 r r-markdown shiny googlevis
我尝试在 rmarkdown 页面中显示 googleVis 图表,但它不起作用...相反,它在浏览器中逐字显示 R 代码。
结果
function ()
{
chart <- func()
paste(chart$html$chart, collapse = "\n")
}
<environment: 0x5bd7558>
Run Code Online (Sandbox Code Playgroud)
代码
```{r echo=F}
library(googleVis)
df <- data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32))
renderGvis({
gvisColumnChart(df, xvar="country", yvar=c("val1", "val2"))
})
```
Run Code Online (Sandbox Code Playgroud)
我不知道你是否还卡住了,我会顺便回答一下,如果对其他人有用的话。
您的代码需要进行 2 处更改:
op <- options(gvis.plot.tag='chart')语句以仅将 HTML 文件的图表组件写入输出文件检查此项results='asis'声明以便返回原始html检查这一点因此你的代码应该是(.Rmd文档):
---
title: "testGoogleVis"
output: html_document
---
```{r echo=F, results='asis'}
library(googleVis)
op <- options(gvis.plot.tag='chart')
df <- data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32))
plot(gvisColumnChart(df, xvar="country", yvar=c("val1", "val2")))
```
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
191 次 |
| 最近记录: |