R Script - gridSVG

JEdward
JEdward New Altair Community Member
edited November 5 in Community Q&A

Hello,

 

It's been a little while since I used R and now I've forgotten how to export plots from R as SVG/PNG so that they can easily be displayed in RM Server without me needing to write to disk.  My example code works in RStudio, but in RM gives me the cryptic error message "We shouldn't be here!"

 

Can someone take a look and see what I'm doing incorrectly?   If there's a simpler way, png is also cool.  

 

<?xml version="1.0" encoding="UTF-8"?><process version="7.3.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="7.3.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="r_scripting:execute_r" compatibility="7.2.000" expanded="true" height="82" name="Export a plot as an SVG" width="90" x="179" y="187">
<parameter key="script" value="# rm_main is a mandatory function, &#10;# the number of arguments has to be the number of input ports (can be none)&#10;rm_main = function()&#10;{&#10;&#9;library(ggplot2)&#10;&#9;library(gridSVG)&#10;&#9;ggplot(iris, aes(Species, Sepal.Length)) + geom_point()&#10;&#9;&#10;&#9;SVGlist &lt;- grid.export(name = NULL)&#10;&#9;str(SVGlist, 1)&#10;&#9;List of 4&#10;&#9;# $ svg :Classes 'XMLInternalElementNode', 'XMLInternalNode', 'XMLAbstractNode' &lt;externalptr&gt; &#10;&#9;# $ coords :List of 18&#10;&#9;# $ mappings:List of 5&#10;&#9;# $ utils : chr &quot;// Note that this code is documented using JSDoc and guided by the following URLs:\n// http://code.google.com/p/jsdoc-toolkit/w&quot;| _truncated__&#10;&#9;&#10;&#9;&#10;&#9;#the SVG code&#10;&#9;returnData &lt;- SVGlist$svg&#10; return(returnData)&#10;}&#10;"/>
</operator>
<operator activated="false" class="text:read_document" compatibility="7.3.000" expanded="true" height="68" name="Read Document" width="90" x="447" y="391">
<parameter key="extract_text_only" value="false"/>
</operator>
<connect from_op="Export a plot as an SVG" from_port="output 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
Tagged:

Answers

  • Thomas_Ott
    Thomas_Ott New Altair Community Member

    You actually got it an R produced image to autopopulate in a Server dashboard? That's pretty cool because that stumped me for a long time.