2

OS: Windows 7, R Version: 3.4.3, R Studio: 1.1.383

The code below produces a nice Gantt chart utilizing R's DiagrammeR package. I'm having issues exporting the output of this package. In R Studio I can click on Zoom and a nice full screen image of my Gantt chart appears. I then proceed to Export > Copy to Clipboard and when I paste I get this weird cropped version of the image pasting to my destination.

The weird thing about the crop is it's taking a partial screenshot of the actual image plus part of my R Studio session and adding the two together. It's like the coordinates are off. I also tried Export > Save as Image and the same issue occurs. Bug?? I output many graphics from ggplot2 in the same fashion and this never occurs.

My temporary solution is to use Window's snipping tool to take my own screenshots of the 'Zoom' but that's not preferable. DiagrammeR uses mermaid markdown, whatever that means, for what it's worth.

library(DiagrammeR)
mermaid("
gantt
dateFormat  YYYY-MM-DD
title A Very Nice Gantt Diagram

section Basic Tasks
This is completed             :done,          first_1,    2014-01-06, 2014-01-08
This is active                :active,        first_2,    2014-01-09, 3d
Do this later                 :               first_3,    after first_2, 5d
Do this after that            :               first_4,    after first_3, 5d

section Important Things
Completed, critical task      :crit, done,    import_1,   2014-01-06,24h
Also done, also critical      :crit, done,    import_2,   after import_1, 2d
Doing this important task now :crit, active,  import_3,   after import_2, 3d
Next critical task            :crit,          import_4,   after import_3, 5d

section The Extras
First extras                  :active,        extras_1,   after import_4,  3d
Second helping                :               extras_2,   after extras_1, 20h
More of the extras            :               extras_3,   after extras_1, 48h
")
stackinator
  • 5,429
  • 8
  • 43
  • 84
  • 3
    The output is actually html and what you see in the output window is the result of parsing the html. If you click the "Export" option in the RStudio viewer window you can choose "save as web page" and save the output to an html file that you can then open in a browser. (Hopefully someone will come along with a programmatic and reproducible way to save the output.) – eipi10 Jan 25 '18 at 16:54
  • Hopefully you'll get a better answer here, but you can also consult the [documentation for `DiagrammeR](http://rich-iannone.github.io/DiagrammeR/docs.html) and the [mermaid section](http://rich-iannone.github.io/DiagrammeR/graphviz_and_mermaid.html#mermaid) in particular for additional information. – eipi10 Jan 25 '18 at 17:21

1 Answers1

4

You can save the html widget as a html file first, then use webshot to save it down as png file.

htmlwidgets::saveWidget(m, file="m.html")
webshot::webshot("m.html", "m.png")

data:

library(DiagrammeR)
m <- mermaid("
    gantt
    dateFormat  YYYY-MM-DD
    title A Very Nice Gantt Diagram

    section Basic Tasks
    This is completed             :done,          first_1,    2014-01-06, 2014-01-08
    This is active                :active,        first_2,    2014-01-09, 3d
    Do this later                 :               first_3,    after first_2, 5d
    Do this after that            :               first_4,    after first_3, 5d

    section Important Things
    Completed, critical task      :crit, done,    import_1,   2014-01-06,24h
    Also done, also critical      :crit, done,    import_2,   after import_1, 2d
    Doing this important task now :crit, active,  import_3,   after import_2, 3d
    Next critical task            :crit,          import_4,   after import_3, 5d

    section The Extras
    First extras                  :active,        extras_1,   after import_4,  3d
    Second helping                :               extras_2,   after extras_1, 20h
    More of the extras            :               extras_3,   after extras_1, 48h
    ")
chinsoon12
  • 25,005
  • 4
  • 25
  • 35