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.
To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.
To insert an image, you can also use an R code chunk. --- title: "R Markdown Tips and Tricks" output: html_document --- You can also insert an image using R code: ```{r} knitr::include_graphics("img/rmarkdown_hex. png") ``` The image looks smaller by default though.
To knit in RStudio , click the Knit pull down button. You want to use the Knit HTML option for this lesson. When you click the Knit HTML button, a window will open in your console titled R Markdown. This pane shows the knitting progress.
If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With