How to use Neptune with Leaflet maps#
When using the Folium library to create and manipulate Leaflet maps in Python, you can use Neptune to log maps saved as HTML.
See in Neptune  Example script 
Quickstart#
The below example creates a map and logs it under a File
field named leaflet_map
.
import folium
import neptune
m = folium.Map()
m.save("map.html")
run = neptune.init_run()
run["leaflet_map"].upload("map.html")
To display it in Neptune, select the run where the map was logged and navigate to All metadata, or create a custom dashboard with a File preview widget.
Walkthrough#
Below is a more detailed example that you can follow along.
Before you start#
- Sign up at neptune.ai/register.
- Create a project for storing your metadata.
-
Have Folium and Neptune installed:
Tip
To follow the guide without any setup, run the example notebook in Colab
Logging Leaflet maps with Neptune#
-
Import Neptune and start a run:
-
If you haven't set up your credentials, you can log anonymously:
If Neptune can't find your project name or API token
As a best practice, you should save your Neptune API token and project name as environment variables:
Alternatively, you can pass the information when using a function that takes
api_token
andproject
as arguments:run = neptune.init_run( api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8", # (1)! project="ml-team/classification", # (2)! )
- In the bottom-left corner, expand the user menu and select Get my API token.
- You can copy the path from the project details ( → Details & privacy).
If you haven't registered, you can log anonymously to a public project:
Make sure not to publish sensitive data through your code!
-
-
Create a map:
-
Save the map as HTML:
-
Use the
upload()
method to log the HTML map to the Neptune run: -
To stop the connection to Neptune and sync all data, call the
stop()
method:
To open the run, click the Neptune link that appears in the console output.
[neptune] [info ] Neptune initialized. Open in the app:
https://app.neptune.ai/workspace/project/e/RUN-1
Result
You can view the map in the All metadata section.
Displaying a map in the Neptune web app#
Apart from viewing the map in the All metadata section, you can create a custom dashboard and add the map as a widget.
- Create a custom dashboard if you don't have one already.
- Select New widget.
- In the top input box, start typing the name of the field where the map was logged (
leaflet_map
, in the example above) or choose the File preview widget and then find your map field. - To finish, click Add widget.
Downloading a map via API#
To download the logged map via the Neptune API, you need to connect to the run in your code and then access the field where the map was logged.
Assuming that a run with the ID GEO-7
exists:
import neptune
run = neptune.init_run(with_id="GEO-7", mode="read-only")
run["leaflet_map"].download()
For more download options, see the File.download()
reference.
Related