我正在尝试生成pdf格式的夸尔托文档(稍后还有word格式)。我遇到了mermaid图表的问题。
请看下面附上示例.qmd文件以说明问题。
首先,它应该支持{mermaid}标记,但是当我这样做时,在rstudio中无法“运行”单元格,而且我的文档实际上也没有生成。在rstudio中,“后台任务”一直卡在“输出文件:testmermaid.knit.md”。
所以我使用DiagrammeR::mermaid来封装它,然后文档确实生成了,但大小太小,如果我调整生成的图形大小,则变得模糊不清。我进行了多次尝试,但都没有成功,所以如果有人能提供一个简单的解决方案,其中图表会从左边Xcm到右边Ycm,并在pdf和word中正确生成?
编辑:
首先,它应该支持{mermaid}标记,但是当我这样做时,在rstudio中无法“运行”单元格,而且我的文档实际上也没有生成。在rstudio中,“后台任务”一直卡在“输出文件:testmermaid.knit.md”。
所以我使用DiagrammeR::mermaid来封装它,然后文档确实生成了,但大小太小,如果我调整生成的图形大小,则变得模糊不清。我进行了多次尝试,但都没有成功,所以如果有人能提供一个简单的解决方案,其中图表会从左边Xcm到右边Ycm,并在pdf和word中正确生成?
编辑:
在@Shafee的评论之后,我注意到我没有安装quarto包,现在我已经安装了最新的R package quarto 1.0.36并重新安装了RStudio (2022.07.1 build 554),但问题仍然存在。
我还注意到我的个人电脑(相同版本的RStudio和quarto)没有这些问题(虽然在Rstudio IDE中仍然无法运行mermaid块)。
编辑2:
在本地硬盘上进行完整重新安装(而不是Windows网络驱动器),我得到了以下结果:
output file: testmermaid.knit.md
ERROR: 找不到打开的服务器
我的版本现在是:
quarto::quarto_version() 1 ‘1.1.189’
---
title: "TestMermaid"
format: pdf
---
```{r libimport}
library(quarto)
library(DiagrammeR)
knitr::opts_chunk$set(echo = F)
```
## Quarto
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
Attempt #1
```{mermaid attempt1}
flowchart LR
A[Hard edge] --> B(Round edge)
B --> C{Decision}
C --> D[Result one]
C --> E[Result two]
```
Attempt #2
```{r attempt2}
mermaid("
sequenceDiagram
participant ParticipantA
participant ParticipantB
participant ParticipantC
ParticipantA->>ParticipantB: I want something
ParticipantB->>ParticipantC: he want something
ParticipantC->>ParticipantB: here is something
ParticipantB->>ParticipantA: he got something for you
", height = '100%', width = '100%')
```
{quarto}
r 包。另外,你能否添加 quarto 版本(不是{quarto}
r 包的版本,我指的是 quarto CLI 的版本)。要检查 quarto 的版本,可以运行quarto::quarto_version()
。 - shafee