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("https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_rivers_lake_centerlines.zip")
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
m.add_layer(countries_data)
m.add_layer(rivers_data)
m.add_control(ipy.LayersControl())

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:
    display(m)


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