title: Plotly does not respect RMarkdown out.height, is there a workaround?
body: <p>I am making slides using R Markdown (with html output via <code>slidy</code>) and need to include plots created using <code>plotly</code>. A plot on a slide should fill most of the slide, so I have set <code>out.width</code> and <code>out.height</code> to "95%" in the chunk options, and set <code>autosize=T</code> in plotly layout options. The plots scale nicely in width to fill the window when the slides are projected (on a larger screen or onto the wall through a beamer; or when just resizing the browser window) -- while height remains at the default 450px - not 95% of the window height.</p>
  
  <p>BUT: if I resize the window size or full-screen it (works both in the RStudio browser and a Chrome window), then the plotly plot recognizes the relative height and resizes accordingly. Except not for all slides, just the current slide that was in view while I resized the window. Here is an example: the plot does not fill the entire slide on a larger screen - but will after even slightly resizing the browser window:</p>
  
  <pre><code>---
  title: "Untitled"
  output: slidy_presentation
  ---
  
  ```{r, echo=F, out.width = "98%", out.height="95%"}
  suppressMessages({library(plotly)})
  p = plot_ly(x=~iris[,1],y=~iris[,2] , type="scatter", mode="markers") %&gt;% layout(autosize=T)
  p
  ```
  </code></pre>
  
  <p>I have tried various (mostly hacky) methods suggested by people who have tangled with issues related to this such as <a href="https://github.com/plotly/plotly.js/issues/537" rel="noreferrer">here</a> and <a href="https://community.plot.ly/t/plot-sizing-problems/1620/14" rel="noreferrer">here</a>, including:</p>
  
  <ul>
  <li>setting animation to FALSE (was suggested somewhere)</li>
  <li>messing with the internal values of the plotly object (e.g. setting p$sizingPolicy$defaultHeight = "100%")</li>
  <li>setting <code>plot_ly()</code> height to a relative % value (this actually disables relative sizing, even for the resizing window trick!)</li>
  <li>wrapping plotly output in a htmltools::div(style="height:95%") (this also disables the automatic resizing, and makes the plot height even smaller)</li>
  <li>trying to overwrite plotly css by including custom css in the rmd file addressing div.plot-container.plotly, div.svg-container, svg.main-svg, and setting {height="95%";} - I can visibly change other css values like <code>background-color</code>, while setting height has no effect.</li>
  <li>adding a button to the plot following <a href="https://plot.ly/r/custom-buttons/#relayout-button" rel="noreferrer">this example</a> that calls the javascript <code>relayout</code> function that redraws the plot and apparently makes it aware of the window dimensions, making it my intended 95% height. So this works, but would necessitate adding a weird button next to every plot and going through my slides and press each one before I present.</li>
  </ul>
  
  <p>But nothing (besides the last hack) seems to work. While width/horizontal resize always works like a charm.</p>
  
  <p>I can't tell if that's intended behaviour or a bug, and even if the latter, I do not really have time to wait for the next version; I need to find some workaround. An obvious hack is to go through my slides before the presentation and resize the window once per each slide, but there are too many plots with plotly slides for this to be viable. And the interactivity is what I need, so rendering plotly plots as PNGs or whatever is not a solution.</p>
  
  <p>TL;DR: how to force autosizing plotly plots immediately respect the out.height parameter in R Markdown so that a plot_ly() plot would fill a slide?</p>