knitr(R)-如何不在HTML文件中嵌入图片? [英] knitr (R) - how not to embed images in the HTML file?
问题描述
这可能非常简单,但是我似乎在文档中找不到它.我不想在HTML文件本身中嵌入生成的图像.
This is probably very easy but I can't seem to find it in docs. I would like to not embed the generated images in the HTML file itself.
因此,基本上我希望knit2html()生成一个带有单独图像文件的HTML文件(然后将这些图像文件链接到HTML中的/在HTML中显示).基本行为是脚本将图像作为base64字符串嵌入.问题在于,在IE中,大图片不会显示(即似乎丢失了).知道如何将图像与HTML输出分开吗?
So basically I want knit2html() to produce a HTML file with seperate image files (which are then linked to / shown in the HTML). The basic behaviour is that the script embeds the images as a base64 string. The problem with this is that in IE, large images won't show up (i.e. appear to be missing). Any idea how I can seperate the images from the HTML output?
我的示例.Rmd文件('knit.Rmd'):
My example .Rmd file ('knit.Rmd'):
```{r}
plot(3)
```
和我的.R文件从中生成HTML:
And my .R file to generate the HTML from this:
library(knitr)
knit2html('knit.Rmd')
此示例生成一个以图为嵌入式base64字符串的HTML.
This example generates a HTML with the plot as an embedded base64 string.
推荐答案
如果查看knit2html
帮助页面,则会看到:
If you look at the knit2html
help page, you will see that :
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
帮助页面上看到以下参数:
Then you look at the markdownToHTML
help page and read that there is the following argument :
options: options that are passed to the renderer. see
‘markdownHTMLOptions’.
因此,您查看markdownHTMLOptions
(仍然没有丢失吗?),然后看到以下选项:
So you look at the markdownHTMLOptions
(still not lost ?) and see the following option :
‘'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.
使用以下命令,您应该在系统上看到默认选项:
With the following command, you should see the default options on your system :
R> markdownHTMLOptions(default=TRUE)
[1] "use_xhtml" "smartypants" "base64_images" "mathjax"
[5] "highlight_code"
因此,您可以尝试使用以下方式编织markdown文件:
So may be you can try to knit your markdown file with :
knit2html("knit.Rmd", options=c("use_xhtml","smartypants","mathjax","highlight_code"))
不过没有经过测试...
Not tested, though...
这篇关于knitr(R)-如何不在HTML文件中嵌入图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!