Search code examples
rrstudiomarkdowndiagrammer

Gantt Chart with R - Can't Output utilizing DiagrammeR and R Studio


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
")

Solution

  • 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
        ")