title: How to change dataframe on button click
body: <p>I am using code on this page: <a href="https://stackoverflow.com/questions/59406167/plotly-how-to-filter-a-pandas-dataframe-using-a-dropdown-menu">Plotly: How to filter a pandas dataframe using a dropdown menu?</a></p>
  <p>I have a global dataframe df that has all the timestamps and frequencies. Now I have created separate dataframes and created a list out of them. I need to switch to different dataframe in array if the button is clicked
  This is how I have created a new dataframe</p>
  <pre><code>dates = freq.date.unique()
  N = -7 #Number of last days
  index = 0
  updatemenu = []
  buttons = []
  bar = []
  for date in sorted(dates)[N: len(dates)]:
      bar.append(pd.DataFrame(columns=[&quot;timestamp&quot;, &quot;freq&quot;]))
      bar[index][&quot;timestamp&quot;] = pd.date_range(str(date)+&quot; 00:00:00+00:00&quot;, str(date)+&quot; 23:59:00+00:00&quot;, freq=&quot;3min&quot;)
      bar[index][&quot;freq&quot;] = 0
      freq_temp = freq.loc[freq.date == pd.to_datetime(date)]
  
      for i in freq_temp.timestamp:
          for j in bar[index].timestamp:
  
              delta = math.ceil(abs(i-j).seconds/60)
  
              if(delta &lt;= 3):
  
                  v = bar[index].loc[pd.to_datetime(bar[index].timestamp) == pd.to_datetime(j) ,&quot;freq&quot;]
                  v = freq.loc[pd.to_datetime(freq.timestamp) == pd.to_datetime(i) ,&quot;freq&quot;].to_string(index=False)
                  bar[index].loc[pd.to_datetime(bar[index].timestamp) == pd.to_datetime(j) ,&quot;freq&quot;] = v
                  break
                  
      index = index + 1
  </code></pre>
  <p>And this is how I am plotting</p>
  <pre><code>fig = go.Figure()
  
  # set up ONE trace
  fig.add_trace(go.Bar(x=bar[0].timestamp,
                           y=bar[0].freq,
                           visible=True)
               )
  
  updatemenu = []
  buttons = []
  
  # button with one option for each dataframe
  for index in range(0,len(bar)):
      buttons.append(dict(method='restyle',
                          label= str(dates[index]),
                          visible=True,
                          args=[{'y':[bar[index].timestamp],
                                 'x':[bar[index].freq],
                                 'type':'bar'}, [0]],
                          )
                    )
  
  # some adjustments to the updatemenus
  updatemenu = []
  your_menu = dict()
  updatemenu.append(your_menu)
  
  updatemenu[0]['buttons'] = buttons
  updatemenu[0]['direction'] = 'down'
  updatemenu[0]['showactive'] = True
  
  # add dropdown menus to the figure
  fig.update_layout(showlegend=False, updatemenus=updatemenu)
  fig.show()
  </code></pre>
  <p>After second date it doesn't show correct graphs. And it shows first graph once before it shows the graph with the button. Here is what dataframe looks like
  <a href="https://i.stack.imgur.com/58Fc4.png" rel="nofollow noreferrer">bar</a></p>
  <p>This is a bar dataframe at specific index.</p>