@Emil, since this link is not working, can you please help to understand how the code works?
I have similar issue. I have a base map (I create it with scatter_mapbox()) which returns a map with the positions of addresses. I also have dropdown menu which filters only certain countries, partners, etc. Each time I use drop-down menu, the map goes back to its initial center point. I’m wondering how I can avoid the update of the whole map.
Here’s the base map:
def main_map(df):
map_fig = px.scatter_mapbox(df, lat="latitude", lon="longitude", hover_data=["age", "income"],
color_discrete_sequence=["fuchsia"], zoom=12, height=780, center={'lat':57.67, 'lon':12.00})
map_fig.update_layout(mapbox_style="open-street-map")
map_fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
return map_fig
And callback:
@app.callback(
Output('map', 'figure'),
Input('country-filter', 'value'),
Input('partner-filter', 'value'),
Input('product-filter', 'value'))
def update_main_map(country,partner,product):
input_list = []
if country is not None:
a = "`country` == " + "'" + country + "'"
input_list.append(a)
if partner is not None:
b = "`partner` == " + "'" + partner + "'"
input_list.append(b)
if product is not None:
c = "`product` == " + "'" + product + "'"
input_list.append(c)
delimeter = " and "
if len(input_list)>0:
query_string = delimeter.join(input_list)
dff = df.query(query_string)
else:
dff=df.copy()
map_fig = px.scatter_mapbox(dff, lat="latitude", lon="longitude", hover_data=["age", "income"],
color_discrete_sequence=["fuchsia"], zoom=6, height=780, center={'lat':57.67, 'lon':12.00})
map_fig.update_layout(mapbox_style="open-street-map")
map_fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
return map_fig
The inputs to the callback are country, partner, product filters.