View source: R/autolabel_latex_captions.R
| set_widget_hooks | R Documentation |
Modified from my gist: https://gist.github.com/burchill/8392b2a753652e24a35a8a1dd707c1b1.
This functions sets a knitr hook so that any HTML widgets that were
printed (i.e., objects that inherit the 'htmlwidget', like those from
the htmlwidgets or plotly packages) will work with a Jekyll system,
like the one used for GitHub Pages.
set_widget_hooks(
dep_dir = knitr::opts_chunk$get("plotly.savepath"),
base_path = knitr::opts_chunk$get("proj.basedir"),
hrefFilter = function(x) paste0("/", x)
)
dep_dir |
The directory you want to save the dependencies to. |
base_path |
The directory you want to make the dependency links relative to.
For example, if your post is at the url |
hrefFilter |
This function lets you perform any additional manipulations to the dependency links. For some reason, when I give my base directory as my project's home directory, the links come back without the necessary "/" in front of them. This function adds that to each link. |
It essentially sets a hook so that, when the document is finished being
knitted, it moves all the dependencies necessary for the widgets to a
directory, and then adds HTML code to the document to load those files
from their new location. Additionally, it sets the default
screenshot.force chunk option to FALSE, so knitr doesn't try to
use a screenshot instead of the widget.
See https://www.zachburchill.ml/plotly_with_jekyll/ for background and (https://gist.github.com/burchill/9df0f6245ea7768e5b6bbd0a1c22db08) for the old, bad version of this script.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.