title: Using R plotly dropdown menu to select variable and keep ussing the colour variable as a trace
body: <p>I was adding a variable selector to a plotly graph in R (following the usual approach that consist in hiding the unnecessary traces from the plot)</p>
  
  <pre class="lang-r prettyprint-override"><code>library(plotly)
  
  dat &lt;- mtcars
  dat$cyl &lt;- factor(dat$cyl)
  dat$car &lt;- rownames(mtcars)
  
  dat %&gt;% 
      plot_ly(x = ~car, y = ~mpg,
              name='mpg', type='scatter', mode='markers') %&gt;%
       add_trace(y = ~hp, name = 'hp', type='scatter', mode='markers') %&gt;%
       add_trace(y = ~qsec, name = 'qsec', type='scatter', mode='markers') %&gt;%
         layout(
            updatemenus = list(
              list(
                  type = "list",
                  label = 'Category',
                  buttons = list(
            list(method = "restyle",
                 args = list('visible', c(TRUE, FALSE, FALSE)),
                 label = "mpg"),
            list(method = "restyle",
                 args = list('visible', c(FALSE, TRUE, FALSE)),
                 label = "hp"),
            list(method = "restyle",
                 args = list('visible', c(FALSE, FALSE, TRUE)),
                 label = "qsec")
          )
        )
      )
    )
  
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ckbg8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ckbg8.png" alt="enter image description here"></a></p>
  
  <p>The code does the job BUT it overrides the standard use of a group/color variable as a trace selector because we already set up the traces.</p>
  
  <p>The standard use of a color/group variable will be something like this </p>
  
  <pre class="lang-r prettyprint-override"><code>plot_ly(group_by(dat,cyl), x = ~car, y = ~mpg, color = ~cyl, type='scatter', mode='markers')
  </code></pre>
  
  <p>NOTE: I use <code>group_by()</code> becuse <code>group = ...</code> is deprecated.</p>
  
  <p><a href="https://i.stack.imgur.com/97XSm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/97XSm.png" alt="enter image description here"></a></p>
  
  <p>Is possible to add the dropdown menu as a variable selector and still been able to use a color/group variable to hide &amp; show the data of the selected variable?</p>
  
  <p>I tried adding <code>color= ~cyl</code> but, as you can imagine, it doesn’t work.</p>
  
  <p>Thanks in advance!!</p>