我想试着在用 mermaid 函数绘制流程图时引入 markdown,但是没鼓捣出来,然后发现其实可以引入 HTML 和 CSS 来实现,然鹅又碰到一个奇怪的错误。如下,我先定义了一个样式D
,然后在定义节点时D[<D>改变字号</D>]
这样来引入自定义样式,问题是随后 knit 生成的 html 文档里面,虽然也确实把图画出来了,可是居然顺道把mermaid(diagram = "")
里面的代码也打印出来了。如果把自定义样式去掉,执行后就会正常只出图。本菜鸟暂时没搞明白问题出在哪?
```{css}
D {
color:red;
font-size:18px;
}
```
```{r}
library(DiagrammeR)
mermaid(
diagram = "
graph LR
A[节点1]
B[第一行<br>第二行</br>第三行]
C[<b>加粗</b> <i>斜体</i>]
D[<D>改变字号</D>]
A --> B
B --> C
B --> D
style A fill:pink, stroke:black, stroke-width:4px
style B fill:lightgreen, stroke:red, stroke-width:2px, stroke-dasharray: 5 5
style C fill:lightblue
style D
", width = 600, height = 200)
```
> sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8 LC_CTYPE=C LC_MONETARY=Chinese (Simplified)_China.utf8
[4] LC_NUMERIC=C LC_TIME=Chinese (Simplified)_China.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] DiagrammeR_1.0.10
loaded via a namespace (and not attached):
[1] visNetwork_2.1.0 digest_0.6.28 R6_2.5.1 jsonlite_1.7.3 magrittr_2.0.1 evaluate_0.14 rlang_1.1.1
[8] cli_3.1.0 fontawesome_0.2.2 rstudioapi_0.13 jquerylib_0.1.4 bslib_0.3.0 DT_0.27 rmarkdown_2.13
[15] RColorBrewer_1.1-2 tools_4.2.0 glue_1.6.2 htmlwidgets_1.5.4 crosstalk_1.2.0 rsconnect_0.8.29 xfun_0.36
[22] yaml_2.2.1 fastmap_1.1.0 compiler_4.2.0 htmltools_0.5.2 knitr_1.35 sass_0.4.0