title: Add an htmlwidget from R to a PowerPoint Slide
body: <p>How can I add the htmlwidget diagram output from DiagrammeR::grViz() to a PowerPoint slide? I'd prefer to keep vector graphics and minimize manual touches.</p>
  
  <p>The code in <code>main.R</code> below renders the DOT diagram nicely as an <code>htmlwidget</code></p>
  
  <pre><code># ./code/digraph-test.dot 
  digraph my_plot_name {
  A-&gt;B-&gt;C;
  }
  
  # main.R
  library(DiagrammeR)
  digraph_test &lt;- grViz("./code/digraph-test.dot")
  </code></pre>
  
  <p>I'd like to add this output to a PowerPoint slide. I adapted the following code from <a href="https://support.rstudio.com/hc/en-us/community/posts/204551627-Add-option-Export-Save-Plot-as-Powerpoint-using-functionality-of-ReporteRs-package" rel="nofollow noreferrer">this post</a>. </p>
  
  <pre><code>library( ReporteRs )
  require( ggplot2 )
  mydoc = pptx( )
  mydoc = addSlide( mydoc, slide.layout = "Title and Content" )
  mydoc = addTitle( mydoc, "Plot examples" )
  myplot = grViz("./code/digraph-test.dot")
  # myplot = qplot(Sepal.Length, Petal.Length
  #                , data = iris, color = Species
  #                , size = Petal.Width, alpha = I(0.7))
  mydoc = addPlot( mydoc, function( ) print( myplot ), vector.graphic=TRUE)
  writeDoc( mydoc, file = "test plot.pptx" )
  </code></pre>
  
  <p>It produces the following error: </p>
  
  <pre><code>Error in .jcall(slide, "I", "add", dml.object) : 
    javax.xml.bind.UnmarshalException
   - with linked exception:
  [org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 2; The markup in the document preceding the root element must be well-formed.]
  </code></pre>
  
  <p>It seems some people have success with the <a href="http://skp.mvps.org/liveweb.htm" rel="nofollow noreferrer">LiveWeb add-in for PowerPoint</a>. I ran into the ActiveX issue, only found hack solutions, and chose not to pursue. There must be a straightforward solution, right?   </p>