繁体   English   中英

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

[英]How can I create a self-contained html report with rmarkdown?

如何从 .Rmd 文件生成带有独立图像的 html 文档? 我正在使用bsplus包和rmarkdown来创建图像轮播。 当我在.Rproj工作目录中打开.html输出时,它工作得很好,但是当我将文件发送给某人时,图像不再显示。

是否有可能获得带有相应图像的“自包含”.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")
  ) 
```

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

library(knitr)
library(rmarkdown)

render("caro.Rmd", html_document(pandoc_args = "--self-contained"))
browseURL("caro.html")

这不是 R/Rmarkdown 问题 - 这是一个 HTML 问题。 大多数 HTML 文件从文件中读取图像,而不是从代码中读取图像。

如果您绝对需要这样做,请参阅此问题和/或此网站

但是,我建议对存储图像的目录和 .html 文件进行 gzip 压缩,然后通过电子邮件发送该存档。

To post the report on sharepoint:
    setwd("C:/Users/...")
#render table
    rmarkdown::render("tablename.rmd") #run the rmd file in the extracts folder
    file.remove("tablename.aspx") #remove the current aspx sharepoint from previous render
    file.rename("tablename.html",`enter code here`"tablename.aspx") #rename the html to be the new one

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM