Dash Scattermapbox adding map clusters

I am trying to use the new add cluster option (plotly 5.11) to add clusters on the map. The problem is that when I run “fig.show()” to view the map I can see the map with all the clusters. However, when I load it to dash (dcc.Graph), I only see a normal map without the clusters. Any help please? @chriddyp @AnnMarieW @adamschroeder

HI @GabrielBKaram,

I can’t reproduce this. What do you see if you use this code?

from dash import html, dcc
import dash
import plotly.express as px
import pandas as pd

df = pd.read_csv(
    "https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv"
)
fig = px.scatter_mapbox(
    df,
    lat="lat",
    lon="long",
    size="cnt",
    zoom=3,
    mapbox_style="open-street-map"
)
fig.update_traces(cluster=dict(enabled=True))


app = dash.Dash(__name__)
app.layout = html.Div(
    [
        dcc.Graph(
            id='graph',
            figure=fig,
        ),
    ]
)


if __name__ == '__main__':
    app.run(debug=True)
1 Like

Hi @AIMPED ,

This is the output I get when I write the code above:

However if I just write:

df = pd.read_csv(
    "https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv"
)
fig = px.scatter_mapbox(
    df,
    lat="lat",
    lon="long",
    size="cnt",
    zoom=3,
)
fig.update_traces(cluster=dict(enabled=True))
fig.show()

I get the expected result in a new browser tab:

So it works fine but when I want to incorporate it into the dash app, I don’t see the proper result.

Hello @GabrielBKaram,

What version of dash are you using?

Hi @jinnyzor ,

I was on dash==2.2.0 just updated to the newest version and it worked. Thanks !

2 Likes

I’m having a problem with the current version, the aggregated circles are not drawn, just the numbers are displayed for the clusters.