我尝试在rmarkdown页面中显示googleVis图表,但它不起作用......相反,它会在浏览器中逐字显示R代码。
结果
function ()
{
chart <- func()
paste(chart$html$chart, collapse = "\n")
}
<environment: 0x5bd7558>
代码
```{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"))
})
```
答案 0 :(得分:0)
我不知道您是否仍然被困住,如果对其他人有用,我会顺便回答。
您的代码有两项更改要应用:
op <- options(gvis.plot.tag='chart')
语句以仅将HTML文件的图表组件写入输出文件check this results='asis'
声明,以便返回 raw html check this 因此,您的代码应改为(.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")))
```