Session Ready
Exercise

Updating data sources from dropdown callbacks

You'll now learn to update the plot's data using a drop down menu instead of a slider. This would allow users to do things like select between different data sources to view.

The ColumnDataSource source has been created for you along with the plot. Your job in this exercise is to add a drop down menu to update the plot's data.

All necessary modules have been imported for you.

Instructions
100 XP
  • Define a callback function called update_plot with the parameters attr, old, new.
    • If the new selection is 'female_literacy', update the 'y' value of the ColumnDataSource to female_literacy. Else, 'y' should be population.
    • 'x' remains fertility in both cases.
  • Create a dropdown select widget using Select(). Specify the parameters title, options, and value. The options are 'female_literacy' and 'population', while the value is 'female_literacy'.
  • Attach the callback to the 'value' property of select. This can be done using on_change() and passing in 'value' and update_plot.