1. Learn
  2. /
  3. Courses
  4. /
  5. Building Dashboards with Dash and Plotly

Exercise

Conditional dropdown options

A senior purchasing officer in the e-commerce company has posed an interesting problem. Their existing dashboard, showing sales by month for minor categories of items, has a two-level dropdown (major category and minor category) with way too many options in it. It is especially annoying, you are told, that some options appear in the second dropdown that can not be selected.

You assure the stakeholder you can assist - it is a great opportunity for you to use chained callbacks to produce a conditional dropdown.

Instructions

100 XP
  • Use the major_categories list created for you on line 8 to set up the Major Category options for that dropdown below line 28 with the same value and label for each option.
  • Create a callback triggered by the major category dropdown (major_cat_dd) that updates the minor category dropdown (minor_cat_dd) options to be only those relevant below line 47.
  • Reformat relevant_minor_options (created on line 55) into a list of dictionaries below line 57 so it can be used in the Dash dropdown.
  • Create a callback triggered by the minor category dropdown that will update the line figure (sales_line) upon selection of an option below line 61.