Black Lives Matter. Please consider donating to Campaign Zero's mission of ending police violence in America.

Updating data on mapbox without updating the whole map


My idea is to load a map, and then with checkboxes you should be able to click on information you want showed on the map.

So the question is, after loading the map - is it then possible to update the map with the information the user wants.
Or would I have to reload the whole map that includes the new chosen data?

If I have to reload the whole map, is it then possible to keep the map at the exact same view before and after reloading?

I haven’t tried with the default Plotly map tools, but you can do it with Dash Leaflet. You can attach callback to the properties of any element of the map and update it that way. In example 1 here,

the tile layers are changed by radio buttons.

Hi Emil,

I’m trying to run your examples;… But I do get errors;

Traceback (most recent call last):
  File "C:/Users/Desktop/dash-leaflet/", line 5, in <module>
    import dash_leaflet as dl
  File "C:\Users\Desktop\dash-leaflet\dash_leaflet\", line 10, in <module>
    from ._imports_ import *
  ModuleNotFoundError: No module named 'dash_leaflet._imports_'

You need to install dash_leaflet. The error is telling you that it is not installed.

It is installed, version 0.0.3?

It might have to do with how you are running the file. Here is a step-by-step guide, which works on my PC.

  • Create a folder for the project, copy the “” file into the folder and put in your own mapbox API key.
  • Create a new virtual environment in the folder and activate it. On Linux the commands would be
python3 -m venv venv
source venv/bin/activate
  • Install the proper packages

pip install dash dash_leaflet

  • Run the code


Ok, I just cloned your git - installed packages and tried to run…

Doing it the way you explain, gives me an error;

ModuleNotFoundError: No module named ‘settings’

What module is that?

@keend That because i put my API key in a file called Så by the step “put in you own mapbox API key”, i mean that you should create a file called “” with the content


and place it in your project directory (next to “”). Alternatively, you can put the key directly in the example file. In this case you should delete the settings import, i.e. the line

import settings

and replace the line

mapbox_token = settings.MAPBOX_TOKEN


mapbox_token = [PUT YOUR TOKEN HERE]

Got it! Thank you :slight_smile:

Good to hear that it works :slight_smile: