title: Plotly (r): Can values in a drop-down box change automatically to reflect data-frame changes?
body: <p>I am investigating using interactive <code>plotly</code> graphs that allow for the selection of categorical values, which change the plot accordingly. I am planning on using the following code structure that has been used in an example with the 'iris' database in <code>R</code>. </p>
  
  <p>However, this code seems to require hardcoding in the amount of categorical variables in the drop-down list (in this example, there are 3 species of which 3 lists have been created to reflect this). </p>
  
  <p>Thus my question is, if the database changed over time with an increase in the number of categorical variables, which would need to be included in the drop-down list, is there a way to automatically update the drop-down list values without having to hardcode them in?
  Thank you for your time.</p>
  
  <pre><code>library(plotly)    
  p &lt;- iris %&gt;%
    plot_ly(
      type = 'scatter', 
      x = ~Sepal.Length, 
      y = ~Petal.Length,
      text = ~Species,
      hoverinfo = 'text',
      mode = 'markers', 
      transforms = list(
        list(
          type = 'filter',
          target = ~Species,
          operation = '=',
          value = unique(iris$Species)[1]
        )
      )) %&gt;% layout(
        updatemenus = list(
          list(
            type = 'dropdown',
            active = 0,
            buttons = list(
              **list**(method = "restyle",
                   args = list("transforms[0].value", unique(iris$Species)[1]),
                   label = unique(iris$Species)[1]),
              **list**(method = "restyle",
                   args = list("transforms[0].value", unique(iris$Species)[2]),
                   label = unique(iris$Species)[2]),
              **list**(method = "restyle",
                   args = list("transforms[0].value", unique(iris$Species)[3]),
                   label = unique(iris$Species)[3])
            )
          )
        )
      )
  p
  </code></pre>