繁体   English   中英

使用 RMarkdown 时,有没有办法插入图像(png)、编织和生成 html 文件,我可以 email 并仍然显示图像?

[英]When using RMarkdown, is there a way to insert images (png), knit and generate and html file that I can email and still show the images?

免责声明:好的,我对 R 有点陌生,所以我根本不是专家。 我花了 2 个小时搜索以下内容,认为这将是一个简单的搜索。 但事实并非如此。 我想在 R Markdown 文件中插入 png 图像,我将把它编织到 HTML 文件中,以便我可以 Z0C0C83F57C2EF783A。 我看到我可以将图像包含在一个块中,甚至通过包含以下代码在编织后没有问题的 output HTML 文件中看到它:

{r pressure, echo=FALSE, fig.cap="A caption", out.width = '50%'}
knitr::include_graphics("OutputMARSParameters.png")

But, unless I create a zip file with all the png files + the html file used in the R Markdown file, those images will not show in the html the other person receives from me. 有没有办法做到这一点,这样我就不必 email 所有图像,但只有一个 html 文件,它会以某种方式包含所有图像,即一个可发送电子邮件的单个 ZFC35FDC70D5FC69D2569883A82EZC 中的图像全部呈现?

默认情况下,当您编织 HTML 文件时,它应该已经创建了一个独立的文档,除非您在 YAML 文档元数据中添加了self_contained: false

这是我使用默认设置创建的简单 R markdown 文件:

---
title: "Demo"
author: "A5C1D2H2I1M1N2O1R2T1"
date: "7/14/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Including External Graphic

```{r pressure, echo=FALSE, fig.cap="A caption", out.width = '50%'}
knitr::include_graphics("html-file-with-code-symbol.png")
```

Note that the `echo = FALSE` parameter was added to the code chunk 
to prevent printing of the R code that generated the plot.

您可以在此 Gist中查看最终的 HTML,并查看此处呈现的内容。

有趣/相关部分从该文件的第 522 行开始。 请注意,它不会将图像文件称为src ,而是以<img src="data:image/png;base64,.... ....的长字符串是base64 字符串代表您的图像。实际上,您可以复制src标签中的文本内容并将其粘贴到base64 转换器中以查看图像。

如果您想验证您的操作是否正确,只需尝试暂时重命名您已包含在文档中的其中一个 png。 如果它仍然显示在您的 HTML output 中,您应该对 go 好。

暂无
暂无

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

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