knitr(R) – 如何在HTML文件中嵌入图像?

这可能很简单,但我似乎无法在文档中找到它.我不想将生成的图像嵌入到HTML文件本身.

所以基本上我想要knit2html()生成一个HTML文件与单独的图像文件(然后链接到/显示在HTML中).基本的行为是脚本将图像作为base64字符串嵌入.这样做的问题是在IE中,大图像将不会显示(即看起来是丢失的).任何想法如何从HTML输出中分离图像?

我的例子.Rmd文件(‘knit.Rmd’):

```{r}
plot(3)
```

和我的.R文件从此生成HTML:

library(knitr)

knit2html('knit.Rmd')

此示例生成一个HTML作为嵌入的base64字符串.

解决方法

如果您查看knit2html帮助页面,您将看到:
This is a convenience function to knit the input markdown source and
call ‘markdownToHTML()’ in the ‘markdown’ package to convert the
result to HTML.

然后你看看markdownToHTML帮助页面,并阅读有以下参数:

options: options that are passed to the renderer.  see
           ‘markdownHTMLOptions’.

所以你看看markdownHTMLOptions(还没丢失?),看看下面的选项:

‘'base64_images'’ Any local images linked with the ‘'<img>'’ tag
      to the output HTML will automatically be converted to base64
      and included along with output.

使用以下命令,您应该会看到系统上的认选项:

R> markdownHTMLOptions(default=TRUE)
[1] "use_xhtml"      "smartypants"    "base64_images"  "mathjax"       
[5] "highlight_code"

所以可能你可以尝试编织你的markdown文件

knit2html("knit.Rmd",options=c("use_xhtml","smartypants","mathjax","highlight_code"))

没有测试,虽然…

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些