R Script - gridSVG
JEdward
New Altair Community Member
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, # the number of arguments has to be the number of input ports (can be none) rm_main = function() { 	library(ggplot2) 	library(gridSVG) 	ggplot(iris, aes(Species, Sepal.Length)) + geom_point() 	 	SVGlist <- grid.export(name = NULL) 	str(SVGlist, 1) 	List of 4 	# $ svg :Classes 'XMLInternalElementNode', 'XMLInternalNode', 'XMLAbstractNode' <externalptr> 	# $ coords :List of 18 	# $ mappings:List of 5 	# $ utils : chr "// Note that this code is documented using JSDoc and guided by the following URLs:\n// http://code.google.com/p/jsdoc-toolkit/w"| _truncated__ 	 	 	#the SVG code 	returnData <- SVGlist$svg return(returnData) } "/>
</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:
0
Answers
-
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.
0