如何使用rmarkdown创建自包含的html报告? [英] How can I create a self-contained html report with rmarkdown?
问题描述
如何从.Rmd文件生成包含独立图像的html文档?我正在使用bsplus
包和rmarkdown
来创建图像轮播.当我打开.Rproj
工作目录中的.html
输出时,它可以完美工作,但是当我将文件发送给某人时,图像不再显示.
How can I produce an html document from a .Rmd file, with self-contained images? I am using the bsplus
package along with rmarkdown
to create a carousel of images. It works perfectly when I open the .html
output within the .Rproj
working directory, but the images are no longer displayed when I send the file to someone.
能否获得带有相应图像的自包含" .html文件输出?还是我也应该发送所有文件夹依赖项?
Would it be possible to get a "self-contained" .html file output with the corresponding images? or should I send also all folder dependencies?
代码外观示例...
---
title: "test"
author: "me"
date: "today"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document 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:
```{r carousel}
bs_carousel(id = "the_beatles", use_indicators = TRUE) %>%
bs_append(
content = bs_carousel_image(src = image_uri("img/john.jpg")),
caption = bs_carousel_caption("John Lennon", "Rhythm guitar, vocals")
) %>%
bs_append(
content = bs_carousel_image(src = image_uri("img/paul.jpg")),
caption = bs_carousel_caption("Paul McCartney", "Bass guitar, vocals")
) %>%
bs_append(
content = bs_carousel_image(src = image_uri("img/george.jpg")),
caption = bs_carousel_caption("George Harrison", "Lead guitar, vocals")
) %>%
bs_append(
content = bs_carousel_image(src = image_uri("img/ringo.jpg")),
caption = bs_carousel_caption("Ringo Starr", "Drums, vocals")
)
```
推荐答案
假设问题中显示的文件位于当前目录中,并且名为caro.Rmd
,并且*.jpg
文件都位于适当的位置,您能够运行pandoc,那么这对我有用:
Assuming that the file shown in the question is in the current directory and called caro.Rmd
and the *.jpg
files are all present at the appropriate location and you are able to run pandoc then this works for me:
library(knitr)
library(rmarkdown)
render("caro.Rmd", html_document(pandoc_args = "--self-contained"))
browseURL("caro.html")
这篇关于如何使用rmarkdown创建自包含的html报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!