gvisMotionChart returns blank plot in R slidify

384 views Asked by At

I'm trying to produce a google motion chart in R slidify. I looked up a lot of examples online and it seems some people have successfully embedded google motion chart in an R slidify slide. Then when I tried my own using similar code, it gives me blank result. I also use the same method to produce a google pie chart and it works well (a pie chart shows in the plotting area)

Here is my simplified code below (Here I am using the Fruits dataset just like all other demo) :

---
title: "Title"
author: "Me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
  ioslides_presentation:
    incremental: yes
    transition: default
    widescreen: yes
  slidy_presentation:
    incremental: yes
job: Job Title
license: by-nc-sa
mode: selfcontained
hitheme: tomorrow
highlighter : highlight.js
subtitle: Subtitle
framework: io2012
widgets: []

---

## GoogleVis Motion chart example

```{r motionchartcode1, results='asis', warning=FALSE, comment=NA}
library(googleVis)
options(gvis.plot.tag='chart')
M <- gvisMotionChart(Fruits, 'Fruit', 'Year',
         options=list(width=400, height=350))
#plot(M)
print(M, tag = 'chart')
```

---

## GoogleVis Pie chart example

```{r motionchartcode, results='asis'}
library(googleVis)
options(gvis.plot.tag='chart')
Pie <- gvisPieChart(CityPopularity,
                    options=list(width=400, height=200))
print(Pie, tag = 'chart')

```

Then I used slidify("demo.Rmd") to compile it to a html file. The first slide gives no plots but a blank plotting area.

I'm not sure which part is effecting this outcome: the setup in --- part, the options in r markdown chunk or my browser environment?

Hope someone can give me ideas.

1

There are 1 answers

0
LeMarque On

The plot command in R uses the internal R http help server to overcome this limitation.

Here's how I overcame it:

Go to 

 http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html 

Click on the dropbox which says 'Edit location' and choose 'add location'

Click 'browse for folder or browse for file'

Choose the folder (or file) in which was your saved html output

Click OK

Also you can modify your codes, for example I did:

suppressPackageStartupMessages(library(googleVis))

options(gvis.plot.tag='chart')

M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")

plot(M1)

print(M1, file="myGoogleVisChart.html")

Now open your googleVis html file and it should display successfully.

In fact, any googleVis file you open from within the folder you selected will also display as you would expect.

Please note that I am using MS Internet Explorer and it asked me to activate ActiveX before I was able to view the output from above, and it was working for me.

Still, if you can not see then also please check for :

https://cran.r-project.org/web/packages/googleVis/vignettes/googleVis.pdf