Reputation: 494
I'm trying to create a DiagrammeR figure from a source file in R Markdown.
source("Gr01_-_QMOF.r", local = knitr::knit_global())
The contents of the file are:
library(DiagrammeR)
grViz("
digraph dot {
graph [layout = dot]
node [shape = rectangle,
style = filled,
color = '',
height = 0.1,
label = '',
fontname = Helvetica,fontsize = 6]
edge [arrowsize = 0.1, arrowhead = none]
node [fillcolor = LightCoral]
a [label = 'My Mood']
node [fillcolor = DarkSeaGreen]
b [label = 'Relaxed']
c [label = 'Unrelaxed']
node [fillcolor = orange]
edge [color = grey]
a -> {b c}
}")
The file in question does run but does not produce the plot in the rmd
file which is sourcing it.
How do I make it appear?
Upvotes: 0
Views: 121
Reputation: 123783
A related issue and several options to fix that can be found at source
command in RMarkdown fails to render plot.
As one option you could run your script via the code chunk option:
---
title: Source DiagrammeR
output: html_document
date: "2022-12-26"
---
```{r grviz, code = readLines('Gr01_-_QMOF.R'), echo=FALSE}
```
Upvotes: 2