美人鱼图在 Rmarkdown xaringan 演示文稿中未正确呈现 [英] Mermaid diagrams not rendering correctly in Rmarkdown xaringan presentations

查看:66
本文介绍了美人鱼图在 Rmarkdown xaringan 演示文稿中未正确呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在使用 xaringan 渲染的 Rmarkdown html 演示文稿中制作一些简单的流程图.我正在使用 DiagrammeR 包绘制美人鱼图.然而,尽管图表在 Rstudio 查看器中正确显示,但样式并未出现在演示文稿输出中.

I am attempting to make some simple flowcharts in an Rmarkdown html presentation I am rendering with xaringan. I'm drawing mermaid diagrams using the DiagrammeR package. However, although the charts display correctly in the Rstudio viewer the styling does not appear in the presentation output.

例如

DiagrammeR::mermaid("
graph LR;
A((Orange)) --> B((Grey));

classDef orange fill:#f96;
classDef grey fill:#d3d3d3;
class A orange;
class B grey;
")

在控制台运行时按预期生成一个橙色节点和一个灰色节点.然而,

generates one orange node and one grey node as expected when run at the console. However,

---
title: "Simple Example" 
output: 
  xaringan::moon_reader
---


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

## Flow chart

```{r example, fig.align='center', fig.retina=3}
DiagrammeR::mermaid("
graph LR;
A((Orange)) --> B((Grey));

classDef orange fill:#f96;
classDef grey fill:#d3d3d3;
class A orange;
class B grey;
")
```

以默认的美人鱼颜色生成流程图,忽略样式.

generates the flowchart in the default mermaid colors ignoring the styling.

有人知道解决方法吗?我也愿意接受其他用于绘制简单树图的软件包的建议.

Does anyone know a workaround for this? I would also be open to suggestions of other packages for drawing simple tree diagrams.

推荐答案

美人鱼创建一个 htmlwidget 作为输出.您应该将其包装到