title: Filter legend in linked views with plotly
body: <p>I am working on a linked plot (similar to <a href="https://plotly-book.cpsievert.me/linking-views-without-shiny.html" rel="nofollow noreferrer">The SharedData plot pipeline</a> from Carson Sievert in plotly for R. The plot shows a legend for one item I currently hover over. However, right now the legend shows two elements, one for the bar chart and one for the line chart. </p>
  
  <ul>
  <li>How do I delete the first legend element (the red square for the bar chart) and keep only the legend for the line chart (red line)?</li>
  </ul>
  
  <p>Here is current code:</p>
  
  <pre><code>library(ggplot2)
  library(crosstalk)
  library(plotly)
  
  sd &lt;- SharedData$new(txhousing, ~city)
  
  base &lt;- plot_ly(sd, color = I("black")) %&gt;%
          group_by(city) %&gt;%
          layout(showlegend = TRUE)
  
  p1 &lt;- base %&gt;%
        summarise(has = sum(is.na(median))) %&gt;%
        filter(has &gt; 0) %&gt;%
        arrange(has) %&gt;%
        add_bars(x = ~has, y = ~factor(city, levels = city), 
         hoverinfo = "none", showlegend = FALSE) %&gt;%
        layout(
        barmode = "overlay",
          xaxis = list(title = "Number of months missing"),
          yaxis = list(title = "")
        ) 
  
  p2 &lt;- base %&gt;%
     add_lines(x = ~date, y = ~median, alpha = 0.3, showlegend = FALSE) %&gt;%
     layout(xaxis = list(title = ""))
  
  gp &lt;- subplot(p1, p2, titleX = TRUE, widths = c(0.3, 0.7)) %&gt;% 
    layout(margin = list(l = 120)) %&gt;%
    highlight(color = "red",
          defaultValues = "Victoria",
          selected = attrs_selected(showlegend = TRUE, mode = "lines"
      ))
  
   gp
  </code></pre>
  
  <p>It was mentioned somewhere that the final removal of the legend element may work, but its not working for me here.</p>
  
  <pre><code>gp$x$data[[1]]$showlegend &lt;- FALSE
  </code></pre>