Skip to content
Advertisement

How to implement dropdown menu in Plotly Dash using Python?

In this app, I’m trying to display a plot that changes when the value in the dropdown menu is changed. The values are the boroughs in London. The data can be found here. Below is the code for base plot.

JavaScript

I am able to change the the borough name manually to change the plot. I then created the Dash app with the the dropdown menu. However, I can’t figure out how to change the plot when a dropdown option is selected. I created a version using conditional statements where I add an if-elif statement for each borough. I am still unable to change the plot itself however. Basically, I need to incorporate this piece of code df = df.loc[df['Borough'] == 'Islington'] to the Dash app. The Dash app code is shown below.

JavaScript

Advertisement

Answer

You can create a copy of your data frame containing only the data corresponding to the dropdown selection, and then use this filtered data frame for generating the figure:

JavaScript
Advertisement