如何使用rmarkdown创建自包含的html报告?

AJM*_*JMA 6 r knitr r-markdown

如何使用自包含图像从.Rmd文件生成html文档?我正在使用该bsplusrmarkdown以创建图像的旋转木马.当我.html.Rproj工作目录中打开输出时,它工作正常,但是当我将文件发送给某人时,图像不再显示.

是否有可能获得带有相应图像的"自包含".html文件输出?或者我应该发送所有文件夹依赖项?

代码如何看起来的例子......

---
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")
  ) 
```
Run Code Online (Sandbox Code Playgroud)

G. *_*eck 6

假设问题中显示的文件在当前目录中并被调用,caro.Rmd并且这些*.jpg文件都存在于适当的位置并且您可以运行 pandoc 那么这对我有用:

library(knitr)
library(rmarkdown)

render("caro.Rmd", html_document(pandoc_args = "--self-contained"))
browseURL("caro.html")
Run Code Online (Sandbox Code Playgroud)