24

The example below plots 4 groups in 4 panes together. But the problem is that they seem to be residing in a single grid. Is it possible to control the size of the charts in shiny output? (ie so that there is no scroll bar on the right when the app is run) I tried to control the height and width, but that only seems to control the image within the grid itself... any ideas?

thanks

shinyUI(pageWithSidebar(
  headerPanel("Example"),
  sidebarPanel(   

  ),

  mainPanel(
    tabsetPanel(tabPanel("Main",plotOutput("temp"))

    )#tabsetPanel  

  )#mainPane;

))



shinyServer(function(input, output) {

  output$temp <-renderPlot({
     par(mfrow=c(2,2))
     plot(1:10)
     plot(rnorm(10))
     plot(rnorm(10))
     plot(rnorm(10))
  }, height = 1000, width = 1000)


})
user1234440
  • 22,521
  • 18
  • 61
  • 103

1 Answers1

34

plotOutput has height and width parameters as well; the width defaults to "100%" (meaning 100% of the available width in its container) and the height defaults to "400px" (400 pixels). Try experimenting with these values, changing them to either "auto" or "1000px".

renderPlot's height and width parameters control the size of the generated image file in pixels, but doesn't directly affect the rendered size in the web page. Their default values are both "auto", which means, detect and use the width/height of the corresponding plotOutput. So once you've set the width and height on plotOutput, you generally don't need the width and height to be set on renderPlot at all.

shinyUI(pageWithSidebar(
  headerPanel("Example"),
  sidebarPanel(   

  ),

  mainPanel(
    tabsetPanel(tabPanel("Main",plotOutput("temp", height = 1000, width = 1000))

    )#tabsetPanel  

  )#mainPane;

))



shinyServer(function(input, output) {

  output$temp <-renderPlot({
     par(mfrow=c(2,2))
     plot(1:10)
     plot(rnorm(10))
     plot(rnorm(10))
     plot(rnorm(10))
  })


})
Joe Cheng
  • 8,001
  • 42
  • 37
  • what can I do in the case where I have `navbarPage` controlling the output and thus I have no `plotOutput` to manipulate? http://stackoverflow.com/questions/30179621/how-can-i-display-my-plot-without-toolbars-in-shiny – tumultous_rooster May 12 '15 at 16:53
  • Thanks Joe, auto does not seem to work well now. using `plotOutput("screenplot", width = "100%", height = "auto")` and no chart shows in Chrome. I see in help it states *"Note that, for height, using "auto" or "100%" generally will not work as expected, because of how height is computed with HTML/CSS"* What can you recommend now besides fixed heights? Thanks – micstr Jul 01 '16 at 14:04