title: Is it possible in R to hide plotly subplots using a dropdown
body: <p>I am trying generating series of small <code>plotly</code> plots based on a group in a <code>data.frame</code> and then using <code>plotly::subplot()</code> to bind them together. I would like to then use a <code>dropdown</code> filter to only display some of the subplots.</p>
  <p>So far (using the plotly docs <a href="https://plotly.com/r/map-subplots-and-small-multiples/" rel="nofollow noreferrer">https://plotly.com/r/map-subplots-and-small-multiples/</a> and this answer <a href="https://stackoverflow.com/a/66205810/1498485">https://stackoverflow.com/a/66205810/1498485</a>) I can create the plots and the buttons and show and hide the contents of the subplots.</p>
  <p>But I cannot figure out how to hide/reset the axis so only the selected subplot is displayed. Below is a minimised example of what I am doing.</p>
  <pre><code># create data 
  df &lt;- expand.grid(group = LETTERS[1:4],
                    type = factor(c('high','med','low'), levels = c('high','med','low')),
                    date = seq(as.Date('2020-01-01'), Sys.Date(), 'month')) %&gt;%
    mutate(value = abs(rnorm(nrow(.)))) %&gt;%
    group_by(group)
  
  # define plot function
  create_plots &lt;- function(dat){
    legend &lt;- unique(dat$group) == 'A'
    plot_ly(dat, x = ~date) |&gt; 
    add_lines(y = ~value, color = ~type, legendgroup = ~type, showlegend = legend) %&gt;%
    add_annotations(
      text = ~unique(group),
      x = 0.1,
      y = 0.9,
      yref = &quot;paper&quot;,
      xref = &quot;paper&quot;,
      xanchor = &quot;middle&quot;,
      yanchor = &quot;top&quot;,
      showarrow = FALSE,
      font = list(size = 15)
    )
  }
  
  # create buttons to filter by group (based on https://stackoverflow.com/a/66205810/1498485)
  buttons &lt;- LETTERS[1:4] |&gt; 
    lapply(function(x){
      list(label = x,
           method = 'update',
           args = list(list(
             name = c('high', 'med', 'low'), 
             visible = unlist(Map(rep, x == LETTERS[1:4], each = 3))
               )))
    })
  
  # generate subplots
  df %&gt;%
    do(mafig = create_plots(.)) %&gt;%
    subplot(nrows = 2) %&gt;%
    layout(
      updatemenus = list(
        list(y = 0.8,
             buttons = buttons))
      )
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/mBd5C.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mBd5C.gif" alt="charts changing based on dropdown" /></a></p>