title: Is there a way to create traces dynamically for example for a stacked bar chart?
body: <p>I have some code that I am working with: </p>
  
  <p>These are traces to create a stacked bar chart. Now I am looking for a way to have these traces be dynamic depending on a variable that is fed by a dropdown menue. </p>
  
  <p>The issue is that not all of the traces are needed for every selection in the dropdown menue. For example Selection A doesnt have values for "Residential" and this gives me an error.</p>
  
  <pre><code>  pv = pd.pivot_table(
          df_plot,
          index=['Year'],
          columns=["Market segment"],
          values=['Value'],
          aggfunc=sum,
          fill_value=0)
  
  trace1 = go.Bar(x=pv.index, y=pv[("Value", "Residential")], name="Residential")
  trace2 = go.Bar(x=pv.index, y=pv[("Value", "Business – small")], name="Business – small")
  trace3 = go.Bar(x=pv.index, y=pv[("Value", "Business – medium")], name="Business - medium")
  trace4 = go.Bar(x=pv.index, y=pv[("Value", "Business – micro")], name="Business - micro")
  trace5 = go.Bar(x=pv.index, y=pv[("Value", "Business – SME")], name="Business - SME")
  trace6 = go.Bar(x=pv.index, y=pv[("Value", "Business")], name="Business")
  
  
  return {
      'data': [trace1, trace2, trace3, trace4, trace5, trace6],
      'layout':
      go.Layout(
          title='Metric: {}'.format(Metric),
          barmode='stack')
  }
  </code></pre>