In this sample, we will demonstrate how to create a side panel ("sidecar") and display interactive geo data using ipyleaflet.

First, we import the necessary libraries:

from sidecar import Sidecar
import ipyleaflet as ipy 
import geopandas 
import json

Then, we use ipyleaflet to create a map and use geopandas to load some data about countries and rivers.

# Create Map
m = ipy.Map(center=(52.3,8.0), zoom = 3, basemap= ipy.basemaps.Esri.WorldTopoMap)

# Load Countries
countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
countries_data = ipy.GeoData(geo_dataframe = countries,
                       style={'color': 'black', 'fillColor': '#3366cc', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},
                       hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},
                       name = 'Countries')

# Load Rivers
rivers = geopandas.read_file("")
rivers_data = ipy.GeoData(geo_dataframe = rivers,
                       style={'color': 'purple', 'opacity':3, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},
                       hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},
                       name = 'Rivers')

# Add Layers

The next call creates a named panel to the right.

sc = Sidecar(title='Sidecar Output')

Using the "with" statement, we can then display out map in the sidecar widget.

with sc:

This page originated from the notebook geo_ipyleaflet_sidebar.ipynb which is attached to this page for safe keeping.