0

Below is my R code for graphing a function using quantmod, However the limit of this is that i can output only one graph. Is there a way to have your function output more than one graph, Say by setting content to text/html and somehow rendering multiple graphs using that? Can you explain to me how to do that?

tickergraph = function()
{
setContentType ("image/png")
temp <- tempfile ()
png (temp, type="cairo")
ticker <- toupper(POST$t);
getSymbols(ticker)
chartSeries(eval(parse(text=ticker)))
dev.off ()
sendBin (readBin (temp, 'raw', n=file.info(temp)$size))
unlink (temp)
}

if(!is.null(POST$t))
{
tickergraph()
print(POST)
}

print("Cannot Plot when some of the values are NULL")
Brian Diggs
  • 57,757
  • 13
  • 166
  • 188
Nick Trileski
  • 151
  • 1
  • 2
  • 8

1 Answers1

0

One way to solve this is to make a HTML-file that has all your graphs as img's such as:

<html><body>
<img src="firstgraph.r" /><br />
<img src="secondgraph.r" /><br />
…
</body></html>

then have firstgraph.r be something similar to the code you posted above (i.e. something that outputs image/png and secondgraph.r output another image/png with your second graph and so on.

That will render a page which in turn loads all your images (which then will be generated on request).

The other (more typical R-solution) would be to create a paneled graph, with all your graphs joined into one image (for instance through par(mfrows=c(2,1)) for a 2-by-1 graph).

andy
  • 696
  • 5
  • 14