5

I tried to display a googleVis chart in a rmarkdown page but it doesn't work... Instead, it displays the R code verbatim in the browser.

Result

function () 
{
    chart <- func()
    paste(chart$html$chart, collapse = "\n")
}
<environment: 0x5bd7558>

Code

```{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"))
})

```
fatdragon
  • 2,211
  • 4
  • 26
  • 43

1 Answers1

0

I do not know if you're still stuck, I'll answer by the way, should it be usuful for someone else.

There are 2 changes to apply at your code:

  • add the op <- options(gvis.plot.tag='chart') statement to write only the chart component of the HTML file into the output file check this
  • add the results='asis' declaration so that the raw html is returned check this

Therefore your code should instead be (.Rmd document):

---
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")))
```

testGoogleVis

Alessio
  • 910
  • 7
  • 16