Automatically adapt plot axis range to the actual maximum in the data after selection

Hey all,

I’m kind of confused with Dash’s behavior when filtering data.
In few words, I have a bar plot, where each bar is a country. This bar plot is connected to a dropdown that filters out countries. But, even if I filter out the country associated to the maximum, the range won’t change. A couple images might help:

You see, after filtering out United States (even if I filter it by default), Dash still “remembers” that US was the maximum.

This is the relevant code:

html.Div(dcc.Dropdown(id='filter-testeos',
                      options=options_countries,
                      value=['United States'],
                      multi=True
                      )),
dcc.Graph(id='testeos')

And then:

@app.callback(Output(component_id='testeos', component_property='figure'),
              [Input(component_id='filter-testeos', component_property='value')])
def plot_testeos(countries):
    dte = data[~data.isin(countries)]
    fig = go.Bar(x=dte['country'], y=dte['cumulative_tests'])
    fig.update_yaxes(tickformat='.1%', row=3, col=1, autorange=True)
    return fig

My actual code is a 3x1 subplot grid, but I guess that doesn’t matter. Is there any method to make my y-axis update when changing the plotting data?

1 Like