Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
526 views
in Technique[技术] by (71.8m points)

markdown - knitr (R) - how not to embed images in the HTML file?

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.

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?

My example .Rmd file ('knit.Rmd'):

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

And my .R file to generate the HTML from this:

library(knitr)

knit2html('knit.Rmd')

This example generates a HTML with the plot as an embedded base64 string.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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’.

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"

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...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...