dev.size() in interactive markdown

13 views
Skip to first unread message

Atul Sharma

unread,
Jan 16, 2017, 9:25:32 AM1/16/17
to Shiny - Web Framework for R
I am attaching an example of an interactive plot, where I want the user to be able to fix the dimensions of the plot (here in inches) to make it legible depending on their device. In this minimal example, the numericInput allows you to set the height in inches and the output is a simple line  plot. I have tried adjusting the plot size in chunk options (fig,width, out.width), by setting par(fin), and by specifying 'non-auto' dimensions in the call to renderPlot() call. As you will see, the 'plot region too large' error is returned whenever the plot size is increased beyond 5.6". 

In RStudio, this error can be dismissed by adjusting the size of the plot window (which feeds back through par("fin") or par("din") I think, but that's obviously not an option in interactive markdown. I was wondering if I need to over-ride the dev.size() option, but I wasn't clear if that  made sense or how exactly to do it for the browser window. Does anyone have an approach that works?

————————————————

Atul Sharma MD, MSc, FRCPC


Assistant Professor, 

Department of Pediatrics and Child Health,

Pediatric Nephrology



InteractivePlot_minimal1.Rmd

Atul Sharma

unread,
Jan 16, 2017, 12:15:31 PM1/16/17
to Shiny - Web Framework for R
A possible solution:

I replaced renderPlot with renderImage in server.R, where the latter  saves the image to a temporary disk file using png().... dev.off().  I can then send the disk image to the browser using outputImage instead of outputPlot in ui.R.  This can be re-sized to the extent of  the browser window without crashing into device window limits. 

Since this problem has vexed me for over a week, I am attaching the solution (to the minimal case I posted earlier), just in case anyone else has a problem with the device window limits. 

If anyone has an explanation for this difference in behaviour, I would like to understand it, as I would still prefer to use renderPlot if it's possible. 

Atul
InteractivePlot_minimal2.Rmd
Reply all
Reply to author
Forward
0 new messages