Force size of 'device window'

3,189 views
Skip to first unread message

Luc Dekoninck

unread,
Nov 16, 2012, 5:23:58 AM11/16/12
to shiny-...@googlegroups.com
Hello,

First, WOW shiny is fantastic !!!

Second my problem:
I created a multiple plot window. The two plots are stretched according some default 'device window size', which flattens my graphs to much. It there a way to control the device output size  (relative size of the height and witdh) ?

Thanks,

Luc

Joe Cheng

unread,
Nov 16, 2012, 12:23:48 PM11/16/12
to shiny-...@googlegroups.com
On the plotOutput function, you can specify dimensions in CSS format (e.g. "200px" for 200 pixels, "75%" for 75% of the available space). So it's easy to make a fixed-size plot (or just fix the height and let the width go to 100%, which is the default behavior). However, it sounds like you might be asking for a scaling image that keeps a particular aspect ratio (or even a min/max aspect ratio)--that's not currently possible (without JavaScript), though a great idea.



--
 
 

Robbie Edwards

unread,
May 10, 2013, 12:17:44 PM5/10/13
to shiny-...@googlegroups.com
Any update on being able to specify aspect ratio?

Or a indication of how it could be done with javascript?

robbie

Joe Cheng

unread,
May 10, 2013, 1:54:04 PM5/10/13
to shiny-...@googlegroups.com
Wow, it actually is possible now.

In ui.R:

plotOutput("foo", height="auto")

In server.R:

output$foo({
  # create plot
}, height=function() { session$clientdata$output_foo_width * 1.0 })

You can modify "1.0" in the last line to get a different aspect ratio. And make sure to change "output_foo_width" to replace "foo" with your plot's ID.

You also have to modify the line
    shinyServer(function(input, output) {
to be
    shinyServer(function(input, output, session) {

If you get errors from the above then you may need to upgrade to a more recent build of Shiny than is on CRAN; try installing it from GitHub:

install.packages("devtools")
devtools::install_github("shiny", "rstudio")


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Robbie Edwards

unread,
May 10, 2013, 2:26:26 PM5/10/13
to shiny-...@googlegroups.com
This is almost working, but I'm getting the error 
  Error in if (height == "auto") height <- shinysession$clientData[[paste(prefix,  : 
  argument is of length zero

If I change the height function to some value, it works*, like so
  height=function() { session$clientdata$output_foo_width * 1.0 })
* meaning it sets the plot's height to that size.

Using shiny.trace I see that the value is set.  I guess I'm referencing it wrong?  I'm using session$clientdata$output_<plotname>_width.  

robbie

Robbie Edwards

unread,
May 10, 2013, 3:57:26 PM5/10/13
to shiny-...@googlegroups.com
bah.  Found the problem.

clientData.. big D.

Thanks for your help Joe.

Kirill Savin

unread,
Jun 14, 2013, 11:39:58 PM6/14/13
to shiny-...@googlegroups.com
I just had the same issue. The new solution works like a charm, thank you.
It seems that you don't include all the information to clientData. It would be nice to have access to tabPanel/parent frame sizes as well, to resize objects that do not have "auto" width, such as googleVis plots.


On Friday, May 10, 2013 1:54:04 PM UTC-4, Joe Cheng [RStudio] wrote:
Reply all
Reply to author
Forward
0 new messages