Dynamically changing plot height?

318 views
Skip to first unread message

Victor Kryukov

unread,
Jun 6, 2013, 5:16:53 PM6/6/13
to shiny-...@googlegroups.com
Hello,

is there an easy way to change the height of the plot? I know about the 'height = ' argument to plotOutput, but I'm plotting charts based on dynamically generated results. Sometimes I want charts to be just 400px, as it would be enough to show my data, while in othercase I want them as tall as 1100px. In other cases yet, I don't want to show the plot at all and don't want to have an empty space in place of chart.

Any ideas?

Victor Kryukov

unread,
Jun 6, 2013, 8:10:31 PM6/6/13
to shiny-...@googlegroups.com
Nevermind - I just realized that uiOutput / renderUI is what I need.

Joe Cheng

unread,
Jun 6, 2013, 11:04:00 PM6/6/13
to shiny-...@googlegroups.com
You don't need to use renderUI for this case, instead use the renderPlot method's height argument and pass it a function, not a number. The function will be evaluated reactively and the return value is expected to be a number, which will be used as the height of the plot in pixels. The only other thing you need to do is pass height="auto" to plotOutput (since the height is going to be determined by the renderPlot height function).

I believe this is documented somewhat in ?renderPlot.
--
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.
 
 


--
Sent from my phone

Victor Kryukov

unread,
Jun 7, 2013, 3:10:42 AM6/7/13
to shiny-...@googlegroups.com
Thanks Joe, this is brilliant. For some reason I didn't look at renderPlot, just plotOutput, and yes, it is documented pretty clearly in renderPlot. 
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Josh Lindsteadt

unread,
Jun 7, 2013, 11:20:30 AM6/7/13
to shiny-...@googlegroups.com
Hey guys,  I am still struggling with this. I created assetheight() function to calculate the changing height of the plot, but currently it says it cannot execute because it is not inside a reactive function.  I have tried moving the height function around, but without any luck. How would I modify the following code to be able to dynamically change the height? Thanks.


    output$riskretPlot <- renderPlot(function(){
      makeAssetPlot()
    }, height=assetheight(), width=800)

Joe Cheng

unread,
Jun 7, 2013, 12:06:46 PM6/7/13
to shiny-...@googlegroups.com
Just need to remove the first "function()" (as renderPlot takes an expression, not a function); and then remove the () from assetheight (as the height parameter is a function, not an expression).

    output$riskretPlot <- renderPlot({
      makeAssetPlot()
    }, height=assetheight, width=800)

It is a little inconsistent, I know.

To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

Will L

unread,
May 27, 2015, 2:16:48 PM5/27/15
to shiny-...@googlegroups.com
What should assetheight be to make the aspect ratio 1?
Reply all
Reply to author
Forward
0 new messages