title: Scale and size of plot in RStudio shiny
body: <p>Related, but only talks about the allocated plot space in general, not how to directly set the plot image size and <em>then</em> scale it to fill the desired space</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/17204735/shiny-chart-space-allocation">Shiny Chart Space Allocation</a></li>
  </ul>
  
  <hr>
  
  <p>I'm creating a shiny web app and would like to set the size of the plot <em>and</em> scale. What I mean by that is I'm looking for a way to set a finite height/width for my plot, and <em>then</em> scale that set sized image to the <code>mainPanel( plotOutput ())</code> area.</p>
  
  <p>Take this as an example/analogous situation outside of <code>shiny</code>.</p>
  
  <pre><code>x &lt;- 1:10
  y &lt;- x^2
  png("~/Desktop/small.png", width = 600, height = 400)
  plot(x, y)
  dev.off()
  
  png("~/Desktop/big.png", width = 1200, height = 800)
  plot(x, y)
  dev.off()
  </code></pre>
  
  <p>I can't upload images to SO and set a size, so I'll include a browser screenshot of each using the following html:</p>
  
  <pre><code>&lt;img src="file:///home/jwhendy/Desktop/file.png" width = "800px" /&gt;
  </code></pre>
  
  <p>This is a full width screenshot on my 1600 x 900 px laptop.</p>
  
  <p><strong>Small</strong>
  <img src="https://i.stack.imgur.com/hDLBg.png" alt="smaller picture"></p>
  
  <p><strong>Big</strong>
  <img src="https://i.stack.imgur.com/KPlaV.png" alt="bigger picture"></p>
  
  <p>I'd like to control the size of the image itself, as I find the <code>ggplot2</code> legends when using options like <code>colour = var</code> and <code>size = var</code> to be pretty small. Note the difficulty of reading axis labels for the bigger picture as well. I realize I may get into a situation where the size of the image doesn't scale well due to limited pixels, but I think I at least have <em>some</em> room to travel before I run into that.</p>
  
  <p>Any suggestions? I've tried playing with the following so far, but without luck:</p>
  
  <h2><strong>ui.R</strong></h2>
  
  <pre><code>shinyUI(pageWithSidebar(
  
  headerPanel("Title"),
  
    sidebarPanel(),
  
    mainPanel(
  
       plotOutput(outputId = "main_plot", width = "100%"))
  
    ))
  </code></pre>
  
  <h2><strong>server.R</strong></h2>
  
  <pre><code>shinyServer(function(input, output) {
  
    x &lt;- 1:10
    y &lt;- x^2
  
    output$main_plot &lt;- renderPlot({
  
      plot(x, y) }, height = 400, width = 600 )
  } )
  </code></pre>
  
  <p>It seems that the height/width options specified in <code>server.R</code> override whatever I have set in the <code>plotOutput</code> section of <code>ui.R</code>.</p>
  
  <p>Is there a way to keep the size of the plot image smaller to maintain readability while still filling the desired <code>mainPanel</code> area?</p>