本文介绍了美人鱼图在 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 作为输出.您应该将其包装到 部分.widgetframe 包可以为您做到这一点,其他基于 htmlwidget 的应用程序,如 DT、leaflet、Dygraph 也可以用这种方法嵌入到 xaringan 中.

The mermaid creates a htmlwidget as output. You should wrap it into a <iframe> section. The widgetframe package can do this for you, other htmlwidget-based apps like DT, leaflet, Dygraph can be embeded into xaringan with this method.

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

suppressPackageStartupMessages(library(widgetframe))


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

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

widgetframe::frameWidget(l)
```

这篇关于美人鱼图在 Rmarkdown xaringan 演示文稿中未正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:50