title: Plotly legendgroup for subplots so a single legend controls all charts
body: <p>I'm using <code>plotly</code> in <code>r</code> to generate a number of subplots. A toy example is shown below. </p>
  
  <pre><code>library(shiny)
  library(dplyr)
  library(plotly)
  
  ## Toy Example
  ui &lt;- fluidPage(
    h3("Diamonds"),
    plotlyOutput("plot", height = 600)
  )
  
  server &lt;- function(input, output, session) {
  
    # reduce down the dataset to make the example simpler
    dat &lt;- diamonds %&gt;% 
      filter(clarity %in% c("I1", "IF")) %&gt;%
      mutate(clarity = factor(clarity, levels = c("I1", "IF")))
  
    output$plot &lt;- renderPlotly({
  
      # Generates the chart for a single clarity
      byClarity &lt;- function(df){
  
        Clarity &lt;- df$clarity[1];
  
        plot_ly(df, x = ~carat, y = ~price, color = ~cut, name = ~clarity) %&gt;%
          add_trace(
            type="bar"
            ## Also tried adding this with no success
            # legendgroup = ~cut
          ) %&gt;%
          layout(
            barmode = "stack"
          )
      }
  
      dat %&gt;% 
        split(.$clarity) %&gt;% 
        lapply(byClarity) %&gt;%
        subplot(nrows = NROW(.), shareX = TRUE, which_layout = "merge")
    })
  } 
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>I would like to make the legends such that clicking on a 'Cut' on the legend will show/hide that 'Cut' from <em>both</em> charts instead of just the chart associated with that legend.</p>
  
  <p><img src="https://i.stack.imgur.com/GknJH.png" alt="DefaultVsIdeal"></p>
  
  <p>I looked at legendgroup but can't figure out how to associate it with <code>cut</code> instead of <code>clarity</code> (<code>clarity</code> is the grouping I'm using to make the subplots). </p>
  
  <p><em>I also need the solution to work with raw <code>plot_ly</code> and not <code>ggplotly</code> as there are other <code>plot_ly</code> functionalities I need that aren't available in <code>ggplotly</code>.</em> </p>
  
  <p>Any help would be appreciated. I am using <code>plotly_4.5.2</code>, <code>dplyr_0.5.0</code>, and <code>shiny_0.14</code>.</p>