【问题标题】:How to embed html images in xaringan self-contained slides如何在 xaringan 自包含幻灯片中嵌入 html 图像
【发布时间】:2021-05-17 07:30:41
【问题描述】:

编织后可以预览下面的幻灯片,但是将幻灯片移动到其他地方后,图像不再显示。

---
title: "Journal club"
author: "Timing Liu"
date: "`r Sys.Date()`"
output:
  xaringan::moon_reader:
    lib_dir: libs
    css: 
      - default
      - default-fonts
    self_contained: true
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

<img src = 2021-01-19-23-07-58.png />

?moon_reader 的文档显示如下:

should not contain the string "/>" when it is written with the syntax  <img src="PATH" />

我相信我的路径应该已经符合标准,因此我不确定为什么不呈现 html 图像。使用诸如![](2021-01-19-23-07-58.png) 之类的降价语法加载的图像可以加载到独立幻灯片中的其他位置。

在装有最新 Xaringan 的 Windows 上尝试使用 Firefox 和 Chrome。

谢谢!

【问题讨论】:

  • 你考虑过使用knitr::include_graphics吗?
  • 我发现 html 在定位和格式方面更灵活。但你是对的,我应该试一试。

标签: r-markdown xaringan


【解决方案1】:

由于我无权访问您的图片,这里是一个工作示例:

---
title: "Journal club"
author: "Timing Liu"
date: "`r Sys.Date()`"
output:
  xaringan::moon_reader:
    lib_dir: libs
    css: 
      - default
      - default-fonts
    self_contained: true
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

<img src = "https://blog.hostonnet.com/wp-content/uploads/2014/07/galaxy.jpg" />

输出(第 2/2 页):

【讨论】:

  • 很抱歉给您带来了困惑。路径是我使用的两个图像。一个需要 html 调整,但另一个只使用 markdown 语法。添加/删除引号似乎没有影响?
  • 我明白了。你能试试&lt;img src = "./2021-01-19-23-07-58.png" /&gt;吗?
  • 谢谢!我不认为这会起作用,因为当 2021-01-19-23-07-58.png 在资产下时它不起作用/它对你有用吗? knitr 解决方案可能是出路,但我想知道 html 是否有任何方法,因为它包含在文档中。
  • 是的,对我来说效果很好。我将用一个工作示例来编辑我的答案。
  • 我现在认为答案是多方面的 - Firefox 有时会出现本地图像问题,而 Chrome 可以正确显示它,但是您在 knitr 上的回答对我有帮助:)
【解决方案2】:

Chrome 还会显示一些 Firefox 中缺少的本地图片。

【讨论】:

    猜你喜欢
    • 2019-04-10
    • 1970-01-01
    • 2019-01-18
    • 2023-01-19
    • 2018-12-09
    • 2022-11-23
    • 1970-01-01
    • 2023-01-26
    • 2012-12-01
    相关资源
    最近更新 更多