Black Lives Matter. Please consider donating to Campaign Zero's mission of ending police violence in America.
https://www.joincampaignzero.org

Updating data on mapbox without updating the whole map

Hi,

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; usage_gallery.py… But I do get errors;

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

@keend
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 “usage_gallery.py” 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

python3 usage_gallery.py

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 settings.py. Så by the step “put in you own mapbox API key”, i mean that you should create a file called “settings.py” with the content

MAPBOX_TOKEN = [PUT YOUR TOKEN HERE]

and place it in your project directory (next to “usage_gallery.py”). 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

with

mapbox_token = [PUT YOUR TOKEN HERE]

Got it! Thank you :slight_smile:

Good to hear that it works :slight_smile: