rr-markdowndiagrammer

rmarkdown diagrammeR blank output to PDF


I would like to include a diagram from diagrammeR in R markdown and render it to PDF.

I installed webshot and phantomJS as discussed in this post but the output is a blank image.

install.packages('webshot')
webshot::install_phantomjs(force=TRUE)

I updated knitr and R to the newest version, the image is still blank.

I tried saving the graph into an html file and use webshot to save it into a png, the png file is still a blank image.

I really appreciate any help! Thank you.


library(knitr)
library(DiagrammeR)
library(webshot)

grViz("digraph {
  graph [layout = neato, rankdir = LR, splines = line]
  
  node [shape = rectangle, pin = true]        
  rec1 [label = 'AAA', pos='1,1!'];
  rec2 [label = 'BBB', pos='3,1!'];
  rec3 [label = 'CCC', pos='5,1!'];
  rec4 [label = 'DDD', pos='7,1!'];
  p1 [label = '', pos = '1,2!', shape = point, width = 0];
  p2 [label = '', pos = '5,2!', shape = point, width = 0]
  
  rec1 -> rec2 -> rec3 -> rec4
  rec3 -> p2 -> p1 [arrowhead = none]
  p1 -> rec1
}")

Solution

  • I just tried your code in a PDF document and had the same problem as you did, but when I installed webshot2 using

    remotes::install_github("rstudio/webshot2")
    

    it worked fine:

    screenshot

    Note that I deleted library(webshot) and library(knitr).