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.
The below example creates a map and logs it under a
File field named
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.
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:
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
Also works for
init_project(), and integrations that create Neptune runs underneath the hood, such as
API token: In the bottom-left corner, expand the user menu and select Get my API token.
- Project name: You can copy the path from the project details ( → Edit project details).
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:
upload()method to log the HTML map to the Neptune run:
To stop the connection to Neptune and sync all data, call the
To open the run, click the Neptune link that appears in the console output.
[neptune] [info ] Neptune initialized. Open in the app:
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.
- In the top tabs, navigate to Run details.
- Create a custom dashboard if you don't have one already.
- Select Add 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
For more download options, see the