7

Is there a way to combine animation package and r markdown? I want to generate animation which i want to include and describe in html file generated from r markdown.

Of course I can embed code from saveHTML or saveGIF file in already generated r markdown file, but i want to automate this process.

I'm working on Windows, R 15.1 and the last RStudio.

ROLO
  • 4,183
  • 25
  • 41
Maciej
  • 3,255
  • 1
  • 28
  • 43
  • 1
    http://cloud.github.com/downloads/yihui/knitr/knitr-graphics.pdf which is for latex, but works with knitr/html too. – Dieter Menne Aug 20 '12 at 14:18

1 Answers1

11

Here is the clock example from the knitr graphics manual (see comment on your question) in markdown:

```{r clock, fig.width=7, fig.height=6, fig.show='animate'}
par(mar = rep(3, 4))
for (i in seq(pi/2, -4/3 * pi, length = 12)) {
    plot(0, 0, pch = 20, ann = FALSE, axes = FALSE)
    arrows(0, 0, cos(i), sin(i))
    axis(1, 0, "VI"); axis(2, 0, "IX")
    axis(3, 0, "XII"); axis(4, 0, "III"); box()
}
```

You need to have the ffmpeg executable in your path for it to work. Knitr will use the animation package, which in turn will call ffmpeg to generate an mp4 file which is embedded in your html output.

ROLO
  • 4,183
  • 25
  • 41
  • 1
    I download ffmpeg for Windows from http://ffmpeg.zeranoe.com/builds/# but i don't know what exactly to do, there are several folders, some of them contain .exe files. If you be so kind to explain me what exactly should I do. Thanks! – Maciej Aug 20 '12 at 18:08
  • 1
    You have to unzip the complete zipfile somewhere, and add the 'bin' [folder to your path](http://www.windows7hacker.com/index.php/2010/05/how-to-addedit-environment-variables-in-windows-7/), e.g. I unzipped everything to 'C:\Programs\ffmpeg' and I added '"C:\Programs\ffmpeg\bin"' to my path. – ROLO Aug 20 '12 at 18:19