title: R: facet_wrap does not render correctly with ggplotly in Shiny app
body: <p>When I do a facet_grid in ggplotly() for a Shiny App, with a large number of faceting groups, the plot is messed up. However it works correctly outside Shiny.</p>
  
  <p>How can I fix this?<br>
  I suspect it is linked to the Y scale but I couldn't find the solution.</p>
  
  <p><br>
  Here's a reproducible example based on <a href="https://plot.ly/r/shinyapp-explore-diamonds/" rel="noreferrer">diamonds example from plotly</a>.</p>
  
  <p>Comparison of Shiny vs non Shiny outputs : <a href="https://i.stack.imgur.com/t8Uwf.png" rel="noreferrer">Comparison of facet_grid outside and within Shiny</a></p>
  
  <p>Code</p>
  
  <blockquote>
    <p>Outside Shiny:  </p>
  </blockquote>
  
  <pre><code>library(ggplot2)
  
  data(diamonds, package = "ggplot2")
  
  # new faceting group
    diamonds$rdmGroup &lt;- as.factor(sample(LETTERS, dim(diamonds)[1], replace=TRUE))
  
  # subset of diamonds   
    diamonds &lt;- diamonds[sample(nrow(diamonds), 1000),]
  
  ggplot(diamonds , aes_string(x = diamonds$x, y = diamonds$y, color = diamonds$x)) + 
        geom_point() + facet_grid(rdmGroup~.) +
        guides(color=FALSE) +
        labs(x = "X", y="Y") 
  </code></pre>
  
  <p><br></p>
  
  <blockquote>
    <p>The same code in a Shiny App:</p>
  </blockquote>
  
  <pre><code>library(shiny)
  library(plotly)
  library(ggplot2)
  
  data(diamonds, package = "ggplot2")
  
  # new faceting group
    diamonds$rdmGroup &lt;- as.factor(sample(LETTERS, dim(diamonds)[1], replace=TRUE))
  
  # subset of diamonds   
    diamonds &lt;- diamonds[sample(nrow(diamonds), 1000),]
  
  ui &lt;- fluidPage(
    headerPanel("Diamonds Explorer"),
    sidebarPanel(
      sliderInput('plotHeight', 'Height of plot (in pixels)', 
                  min = 100, max = 2000, value = 1000) 
    ),
    mainPanel(
      plotlyOutput('trendPlot')
    )
  )
  
  
  server &lt;- function(input, output) {
  
    output$trendPlot &lt;- renderPlotly({ 
        p &lt;- ggplot(diamonds, aes_string(x = diamonds$x, y =diamonds$y, color = diamonds$x)) + 
              geom_point()+ facet_grid(rdmGroup~., scales = "free_y") +
              labs(x = "X", y="Y")
  
        ggplotly(p) %&gt;% 
              layout(height = input$plotHeight, autosize=TRUE)
    })
  }
  shinyApp(ui, server)
  </code></pre>
  
  <p>PS: I used aes_string() instead of aes() intentionally as I need it in my real app.</p>