0

I'm trying to create a drop down menu using the following code:

import plotly.express as px

df = px.data.gapminder()
fig = px.line(df, x="year", y="lifeExp", color="country")


buttons = [
    {'method' : 'update', 'label' : val, 'args' : df[df['continent'].eq(val)]['lifeExp']} 
    for val in df['continent'].unique()
]

# construct menus
updatemenus = [{'buttons': buttons,
                'direction': 'down',
                'showactive': True,}]

# update layout with buttons, and show the figure
fig.update_layout(updatemenus=updatemenus)
fig.show()

I've added the list comprehension to generate the y values, but I"m not sure what I'm currently doing wrong here.

I'm expecting to be able to select a different continent and have the plot update

baxx
  • 3,956
  • 6
  • 37
  • 75
  • Unfortunately in this case there is not a few line solution with plotly express only. I do have a solution but it's 82 lines long without comments. – rpanai Jul 10 '20 at 03:21
  • An easier option will be use dash. – rpanai Jul 10 '20 at 03:22
  • 1
    In this [answer](https://stackoverflow.com/a/61754644/4819376) you can find the two approaches but in your case you need to have a 2 for loops one for continents and one for countries within the continent. – rpanai Jul 10 '20 at 03:28

0 Answers0