Insert an animated plot into an R Markdown document

insert_animate(file, options = click_to_play(), style, use_cdn = TRUE)

Arguments

file

The exported plot.

options

A character string; the JavaScript to customise the playback options. Two basic options click_to_play() and click_to_loop() have been implemented for general usage.

style

Optional style for the iframe that hosts the visualisation.

use_cdn

TRUE / FALSE; if TRUE, serve the assets from a CDN, otherwise embed the assets into the HTML.

Examples

# \donttest{
input <- tempfile(fileext = ".Rmd")
output <- tempfile(fileext = ".html")
writeLines('
```{r, echo = FALSE, message = FALSE}
# Run / include the following in a code chunk of an R Markdown document
library(animate)
insert_animate(system.file("tests/Lorenz_system.json.gz", package = "animate"),
               options = click_to_loop())
```
', input)
knitr::knit(input, output)
#> 
#> 
#> processing file: C:\Users\jkwok\AppData\Local\Temp\Rtmp65dS7Z\file7cc452357eb4.Rmd
#> 
  |                                                          
  |                                                    |   0%
  |                                                          
  |.................                                   |  33%                  
  |                                                          
  |...................................                 |  67% (unnamed-chunk-1)
  |                                                          
  |....................................................| 100%                  
                                                                                                            
#> output file: C:\Users\jkwok\AppData\Local\Temp\Rtmp65dS7Z\file7cc44fdc2c36.html
#> [1] "C:\\Users\\jkwok\\AppData\\Local\\Temp\\Rtmp65dS7Z\\file7cc44fdc2c36.html"
# browseURL(output)
# }