Go scattermapbox doesn't update

Hi guys, I will try to give an example as clear as possible, my code is on another network so I can’t copy paste it.

So I have a function that creates a scattermap figure
I pass a list of longitude points and langitudes for my map.
I have 2 layers to the map.

now I have a really simple callback:

@dash.callback(
    Output('map', 'figure'),
    Input('button', 'n_clicks'),
    State('map', 'figure')
)
def temp(n_clicks, map_fig):
    print(map_fig)
    return go.Figure() # Returns an empty figure

I click on the buttons 2 times.
The first time I see in the console the figure data as I expect,
now after I click I expect to see the map as an empty figure, but no it doesn’t update the map.
and the second time I click, it prints the exact same data it printed before meaning the figure really didn’t change.

Now for clarifications:

  1. I checked the id names they’re right (the callback runs after all)
  2. My real goal is to return a new scattermapbox with a different set of points, I am using an empty figure for simplification of the question, when using the scattermapbox with new points I have the exact same problem.
  3. I tried looking at the map element in the inspect while clicking the button it shows on the div created by the graph figure with the id data -dash-is-loading for a second and then it disappears, and nothing changes below the div with the id.
    any idea why this happens?

UPDATE

I get an error Uncaught (in promise) Error: Mapbox error.
Any idea what it means and if its the cause of the problem?

1 Like

Hi! It’s hard to tell, because I can’t see your code, but I guess I had a very similar problem today. My code (simplified) looked like this:

def map_plot(active_stations):
    stations_map_data = go.Scattermapbox(lon = active_stations.lon,lat = active_stations.lat)
    stations_map = go.Figure(data=stations_map_data)
    return stations_map

When I wanted to change the points ploted on the map, I called this function again and passed the result to Dash. When I printed stations_map, it was changed, but the old version was still displayed.

I have no idea why, but changing to this version helped:

def map_plot(active_stations):
    stations_map = px.scatter_mapbox(active_stations,lat=active_stations.lat, lon=active_stations.lon)
    return stations_map

It is basically replacing go.Scattermapbox with px.scatter_mapbox.

Hi! thanks for the answer, I will definitely check this out Saturday when I go back to work and update you if it worked!

@Matan Did the solution suggested by @katterrina work?

Hello @yaseen,

Welcome to the community!

There was an issue with dash 2.7.0, please make sure you are running a newer version than that.

I’m still having the issue even while using the latest version of dash.
I’ve posted a minimal example here: Go Scattermapbox Does Not Update
Could you check it out?

no it didn’t work.
my bad i didn’t update the post.

Hi everyone,
I wasn’t able to solve this issue either so I opened a github issue about this.

So, I believe that this has to do with the very first render of the map. If there is no data, the map doesnt render changes to the data properly.

If the map has some placeholder info, and then you update, it works properly.

This very well could be an issue with mapbox itself, as this is a library outside of plotly.

1 Like