I would like to install a dropdown filter in python plotly - without using dash.
The solution I came up with works in case that xaxis/yaxis ranges do not change, e.g. a heatmap. In case the ranges change, it does not work well anymore.
Example: A barchart with country information. Works well for Italy and Canada. If I switch to Germany with higher population numbers than the initial country Italy, the yaxis range does not increase. How could this be fixed? Or is there a more efficient way in general?
Thanks a lot for helpful suggestions!
Example:
# Data
df = px.data.gapminder()
df = df[['country','year', 'pop']]
df.head(3)
# Create Barchart
def generate_barchart(ins):
fig = px.bar(df[df['country']==ins], x='year', y='pop')
return fig
# Dropdown: Content
uplist1 = ['Italy', 'Canada', 'Germany']
uplist2 = [generate_barchart(ins) for ins in uplist1]
# Dropdown: Implementation
upfilter = [{'method': 'animate', 'label': i1, 'args': [i2]} for i1, i2 in zip(uplist1, uplist2)]
updatemenus = [{'buttons': upfilter}]
# Initial barchart
fig = go.Figure(uplist2[0])
# Add dropdown
fig.update_layout(updatemenus=updatemenus)
# Result
fig

