lazyrmd v0.2.0.1
Monthly downloads
Render R Markdown Outputs Lazily
An R Markdown html document format that provides the ability to lazily
load plot outputs as the user scrolls over them. This is useful for large R
Markdown documents with many plots, as it allows for a fast initial page load and
defers loading of individual graphics to the time that the user navigates near them.
Readme
lazyrmd 
The lazyrmd R package provides an R Markdown html output format that enables plot outputs in the document to be lazily loaded. It is useful for large R Markdown documents with many plots, as it allows for a fast initial page load, deferring the loading of individual graphics to the time that the user navigates near them.
Installation
options(repos = c(tessera = "http://packages.tessera.io",
getOption("repos")))
install.packages("lazyrmd")
or
devtools::install_github("hafen/lazyrmd")
Usage
To enable lazy loading, you need to do two things in your R Markdown document:
Change your output format from
html_document
tolazyrmd::lazy_render
in the front-matter of your document, e.g.:--- title: "Lazy Loading Test" author: "Ryan Hafen" output: lazyrmd::lazy_render ---
Note that the
lazyrmd::lazy_render
is a wrapper aroundrmarkdown
so all front-matter options forrmarkdown::html_document
are valid forlazyrmd::lazy_render
.Add
lazy=TRUE
to any chunk whose output is an htmlwidget that you would like to have load lazily, e.g.:```{r, lazy=TRUE} library(rbokeh) figure(width = 800) %>% ly_points(date, Freq, data = flightfreq, hover = list(date, Freq, dow), size = 5) %>% ly_abline(v = as.Date("2001-09-11")) ```
The output of this block will not be part of the page load when viewing the resulting html document. Instead, a blank space for the plot will be held and when the user gets close to the point in the document at which they will be viewing the plot, it will be loaded into the page.
How it works
Currently the package only works for htmlwidget output, but adding support for lazy loading of raster graphics should be very straightforward.
For htmlwidgets, this package overrides the knit_print.htmlwidget
method in the htmlwidgets package. If the user has not specified that the output should be lazily loaded with lazy=TRUE
, it passes the plot on to this default method. However, if lazy=TRUE
has been specified, a utility function, print_lazy_widget()
is called which saves out the output of the plot as an independent html file and returns a placeholder for the plot. Javascript code is automatically embedded in the html page that will cause the plot to load based on the page scrolling actions of the user.
Note that this approach is not possible with standalone html output - we must store the plots separately. Otherwise, we would defeat the purpose of why this package was created.
For adding support for raster graphics output, I just need to get a little more acquainted with the knit_print
method for these and the rest will be easy.
Acknowledgements
This package uses the very lightweight recliner.js library to handle lazy loading.
Functions in lazyrmd
Name | Description | |
html_dependency_recliner | Provide HTML dependencies for lazyhtml R Markdown format | |
lazy_render | Format for converting from R Markdown to an HTML document with lazy loading of graphics | |
knit_print.htmlwidget | A custom knitr print method for htmlwidgets | |
No Results! |
Vignettes of lazyrmd
Name | ||
lazy_example.Rmd | ||
No Results! |
Last month downloads
Details
License | MIT + file LICENSE |
URL | http://github.com/hafen/lazyrmd |
BugReports | https://github.com/hafen/lazyrmd/issues |
LazyData | true |
RoxygenNote | 5.0.1 |
VignetteBuilder | knitr |
NeedsCompilation | no |
Packaged | 2018-08-19 08:39:12 UTC; hornik |
Repository | CRAN |
Date/Publication | 2018-08-19 08:51:35 UTC |
X-CRAN-Original-Maintainer | Ryan Hafen |
X-CRAN-Comment | Archived on 2020-01-02. |
imports | digest , htmltools , htmlwidgets , knitr , rmarkdown |
suggests | lintr , networkD3 , testthat |
depends | R (>= 3.2.3) |
Contributors | jQuery Foundation, Barret Schloerke, Sourcey |
Include our badge in your README
[](http://www.rdocumentation.org/packages/lazyrmd)