Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

How to remove redundant options from list of dicts when using a callback?

Hello All,

I am using a large csv file with state, county, and then a bunch of data specific to each county. I am trying to use a series of callbacks to allow a user to select by state, then by county, and then they add or remove county-specific data as they desire for scheduling visualizations. My df:

df = [dict(State="CO", County="Franklin", Task="Job A", Start='2020-01-01', Finish='2020-02-28'),
      dict(State="CO", County="Franklin", Task="Job A", Start='2020-03-01', Finish='2020-04-28'),
      dict(State="CO", County="Franklin", Task="Job B", Start='2020-05-05', Finish='2020-06-15'),
      dict(State="CO", County="Franklin", Task="Job B", Start='2020-06-05', Finish='2020-07-15'),
      dict(State="CO", County="Franklin", Task="Job B", Start='2020-08-05', Finish='2020-09-15'),
      dict(State="CO", County="Franklin", Task="Job B", Start='2020-10-05', Finish='2020-12-15'),
      dict(State="CO", County="Wise", Task="Job A", Start='2020-01-01', Finish='2020-02-28'),
      dict(State="CO", County="Wise", Task="Job A", Start='2020-03-01', Finish='2020-04-28'),
      dict(State="CO", County="Wise", Task="Job B", Start='2020-05-05', Finish='2020-06-15'),
      dict(State="CO", County="Wise", Task="Job B", Start='2020-06-05', Finish='2020-07-15'),
      dict(State="CO", County="Wise", Task="Job B", Start='2020-08-05', Finish='2020-09-15'),
      dict(State="CO", County="Wise", Task="Job B", Start='2020-10-05', Finish='2020-12-15'),

Using a dropdown callback, I populate the dropdown options with:

options=[{'label': x['County'], 'value': x['County']} for x in df]

but it loads every “CO” entry for my state dropdown (this example would provide 12 CO’s) and every county for my county dropdown (this example would provide 6 Franklins and 6 Wises). They all work if selected and load all the rows pertinent to the selection on my graph (example: selecting CO and Franklin still loads both Job A’s and all 4 Job B’s).

How do I remove the redundant options for the dropdown while still calling on all the data in the pertinent rows?

Thank you!