[英]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")
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.