Dash Tooltip to Scattermapbox giving wrong labels

I am replicating the example from the plotly website to get a customized tooltip for my Scattermapbox (https://dash.plotly.com/dash-core-components/tooltip)

However, the results that I am getting are completely off (e.g. I hover over Shanghai, I get the results for Barcelona, etc.). I cannot seem to find what’s wrong in the code.

Find simplified sample below:

# Layout
                dcc.Graph(id='map_graph_fav', clear_on_unhover=True)]),

# Callback for map
    Output('map_graph_fav', 'figure'),
    Input('submit_button_fav', 'n_clicks'),
    State('country_dropdown_fav', 'value'),
    State('city_dropdown_fav', 'value'),
    State('property_type_dropdown_fav', 'value')
def update_map(n_clicks, selected_country, selected_city, selected_building):
    df_map = df[(df['Country'].isin(selected_country)) &
                (df['City'].isin(selected_city)) &
                (df['Building Type'].isin(selected_building))]

    if n_clicks is None:
        return dash.no_update

        fig = px.scatter_mapbox(df_map, lat='Latitude', lon='Longitude', size='Annual Rent', color='Favourability', text='City')
        return fig

# Callback for tooltip
    Output('graph-tooltip', 'show'),
    Output('graph-tooltip', 'bbox'),
    Output('graph-tooltip', 'children'),
    Input('map_graph_fav', 'hoverData'),
def display_hover(hoverData):
    if hoverData is None:
        return False, dash.no_update, dash.no_update

    # demo only shows the first point, but other points may also be available
    pt = hoverData['points'][0]
    bbox = pt['bbox']
    num = pt['pointNumber']

    df_row = df.iloc[num]
    name = df_row['City']
    form = df_row['Country']

    children = [
            html.H2(f"{name}", style={"color": "darkblue"}),
        ], style={'width': '200px', 'white-space': 'normal'})

    return True, bbox, children

Example current output:


Hi Gabriel,

Did you manage to resolve this issue. I am facing the exact same challenge.

Hi @ChepelesuKaunda ,

Unfortunately not. it works fine when i don’t have any filters in the app. once i include filtering, it stops working properly.

Hi @GabrielBKaram welcome to the forums.

Could you provide a MRE?

1 Like

Hi @GabrielBKaram ,

What do you mean by filters in the app? Kindly explain…