问题描述
问题:如何在R Distill Markdown文件中将HTML文件放置在适当的位置?
背景:我想在Distill Rmd文件中嵌入/合并外部html文件.我不想在文档中显示指向html的链接,但是要显示html文件的内容.像 include_graphics
这样的代码仅适用于html.
我无法通过Google搜索找到某些内容.我只发现
Question:How do I place HTML files in place within an R Distill Markdown file?
Background:I would like to embed / incorporate an external html file within a Distill Rmd file. I don't want to show the link to the html in the document, but the content of the html file. Something like include_graphics
only for html.
I wasn't able to find something via google search. I only found Include HTML files in R Markdown file? where OP writes, he never figured out how to do it :(
From that post I tried htmltools::includeHTML("file.html")
which didn't work,
and also shiny::includeHTML("file.html")
which didn't work,
and even (it didn't work):
includes:
in_header: file.html
With htmltools::includeHTML
I at least got the error message Error loading script: https://cdn.jsdelivr.net/npm//vega@5?noext which I couldn't make sense of :(
Though I can't reproduce this error-message now (a couple of weeks later). Maybe it is because I included library(htmltools)
. Though there still is no html embedded :(
However the Distill package apparently is able to do embed html, as the _footer.html is included correctly, but automatically (such that i wasn't able to find the command in the code).
Thanks a lot!
You might want to double check your R chunk arguments, does it have include=FALSE
? because then you would be calling the HTML file, but then telling it not to be included, here is my distill Rmd file and the output with the included HTML code.
Rmarkdown
---
title: "Untitled"
output: distill::distill_article
---
```{r setup}
knitr::opts_chunk$set(echo = FALSE)
library(htmltools)
htmltools::includeHTML("test2.html")
```
HTML: titled test2.html
located in same directory as .Rmd
<html>
<head>
</style>
<title>Title</title>
</head>
<body>
<p>This is an R HTML document. When you click the <b>Knit HTML</b> button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:</p>
<div class="chunk" id="unnamed-chunk-1"><div class="rcode"><div class="source"><pre class="knitr r" ><span class="hl kwd">summary</span><span class="hl std">(cars)</span>
</pre></div>
<div class="output"><pre class="knitr r">## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
</pre></div>
</div></div>
<p>You can also embed plots, for example:</p>
<div class="chunk" id="unnamed-chunk-2"><div class="rcode"><div class="source"><pre class="knitr r" ><span class="hl kwd">plot</span><span class="hl std">(cars)</span>
</pre></div>
</div><div class="rimage default"><img src="figure/unnamed-chunk-2-1.png" title="plot of chunk unnamed-chunk-2" alt="plot of chunk unnamed-chunk-2" class="plot" /></div></div>
</body>
</html>
output rendered to html
这篇关于如何在R Distill rmd中嵌入外部HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!