提取.Rmd文件的html依赖项(包含htmlwidgets) [英] Extract html dependencies for .Rmd file (containing htmlwidgets)

查看:93
本文介绍了提取.Rmd文件的html依赖项(包含htmlwidgets)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何创建一个将.Rmd文件(包含htmlwidgets代码)作为输入并输出包含JavaScript/CSS依赖关系的html文件的函数?

How could I create a function which would take a .Rmd file (containing htmlwidgets code) as its input, and output a html file containing its JavaScript/CSS dependencies?

具体来说,当渲染为html时,临时文件rmarkdown会为pandoc的--include-in-header参数生成.

Specifically, the tempfile rmarkdown generates for pandoc's --include-in-header argument, when rendering to html.

示例-myfile.Rmd:

Example -- myfile.Rmd:

This is some text

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

运行rmarkdown::render('myfile.Rmd')将一个临时文件传递给--include-in-header pandoc参数,其中包含呈现交互式图形所需的所有JavaScript和CSS(压缩的data:uri格式,或指向复制文件的html链接).这包含在最终的html文件中,以便所有内容都在浏览器中呈现.我希望能够生成此临时文件.

Running rmarkdown::render('myfile.Rmd') passes a tempfile to the --include-in-header pandoc argument, containing all the JavaScript and CSS needed to render the interactive graphic (either compressed data:uri format, or html links to copied files). This is included in the final html file, so that everything renders in the browser. It's this tempfile I'd like to be able to generate.

它似乎是通过将依赖项对象传递给内部函数rmarkdown:::html_dependencies_as_string来输出的.我希望能够为包含htmlwidgets代码的任意.Rmd文档生成此文件.

It's appears to be output by passing a dependencies object to the internal function rmarkdown:::html_dependencies_as_string. I'd like to be able to generate this file for arbitrary .Rmd documents containing htmlwidgets code.

我对使用knitr和Jekyll的博客感兴趣,因为Yihui概述了此处.但是,这种方法的缺点是htmlwidgets功能都不起作用,因为依赖注入步骤错过了.这是因为pandoc由Ruby/Jekyll调用,因此无法从htmlwidgets/rmarkdown的隐形魔术中受益.我想在构建过程中添加一个将依赖项写入html文件的函数,如果需要,可以由Jeykll将其包含在html标头中.

I'm interested in blogging using knitr and Jekyll, as Yihui outlines here. However, the disadvantage of this approach is that none of the htmlwidgets functionality works, because the dependency injection step is missed. This is because pandoc is called by Ruby/Jekyll, and so does not benefit from htmlwidgets/rmarkdown's invisible magic. I'd like to add a function to my build process which writes the dependencies to a html file, which can be included in the html header by Jeykll if required.

推荐答案

这是可能的解决方法 https://brendanrocks.com/htmlwidgets-knitr-jekyll/.

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

有点hacky.尚未正式解决此问题. yihui/knitr-jekyll中有一个未解决的问题: https://github.com/yihui /knitr-jekyll/issues/8

A bit hacky. An official solution to this problems is still pending. There is an open issue in yihui/knitr-jekyll: https://github.com/yihui/knitr-jekyll/issues/8

这篇关于提取.Rmd文件的html依赖项(包含htmlwidgets)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆