Extract the html dependencies for the .Rmd file (containing htmlwidgets)

Question

How can I create a function that will take a .Rmd file (containing htmlwidgets code) as its input, and output an html file containing its JavaScript / CSS dependencies?

In particular, tempfile rmarkdown generates the pandoc --include-in-header argument when rendering in html.

More details

An example is myfile.Rmd:

 This is some text ```{r} library(dygraphs) dygraph(nhtemp, main = "New Haven Temperatures") ``` 

Running rmarkdown::render('myfile.Rmd') transfers the temporary file to the --include-in-header pandoc argument containing all the JavaScript and CSS needed to render interactive graphics (compressed data: uri format or html link to the copied files ) This is included in the final html file so that everything is displayed in the browser. This is this tempfile that I would like to create.

It seems to be inferred by passing the dependency object to the internal function rmarkdown:::html_dependencies_as_string . I would like to be able to generate this file for arbitrary .Rmd documents containing htmlwidgets code.

Context

I'm interested in blogs using knitr and Jekyll, as Yihui describes here . However, the drawback of this approach is that none of the htmlwidgets functions work, because the dependency injection step is skipped . This is because pandoc is called by Ruby / Jekyll and therefore it does not use the invisible magic of htmlwidgets / rmarkdown. I would like to add a function to my build process that writes dependencies to an html file, which can be included in the Jeykll html header if necessary.

+6
source share
1 answer

This is a possible solution http://benjcunningham.org/2016/06/13/hacking-together-htmlwidgets-for-jekyll.html , which refers to an earlier post that also offers a solution: https://brendanrocks.com/htmlwidgets -knitr-jekyll / .

A bit hacked. An official solution to these problems has not yet been adopted. There is an open question in yihui / knitr-jekyll: https://github.com/yihui/knitr-jekyll/issues/8

0
source

All Articles