Search code examples
r-markdownxaringan

How to embed html images in xaringan self-contained slides


The following slide can be previewed after knit but after moving the slide to elsewhere, the images can no longer be displayed.

---
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 />

The documentation of ?moon_reader shows the following:

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

I believe my path should already fit meet the criteria and therefore I am not sure why html images are not rendered. The images loaded with markdown syntax like ![](2021-01-19-23-07-58.png) can be loaded elsewhere in the self-contained slides.

Tried with Firefox and Chrome on Windows with latest Xaringan.

Thank you!


Solution

  • Since I don't have access to your image, here is a working example:

    ---
    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" />
    

    Output (page 2/2):enter image description here