Folium#
Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).
import folium
import panel as pn
pn.extension(sizing_mode="stretch_width")
The Folium pane renders folium interactive maps. Any folium object with an HTML representation, such as a folium.Map or folium.Figure, can be displayed.
Parameters:#
For details on other options for customizing the component see the layout and styling how-to guides.
object(object): The Folium object being displayed.
By default the Folium pane uses sizing_mode='stretch_width', so it is usually only necessary to set a height.
The Folium pane uses the built-in HTML representation provided by folium to render the map:
m = folium.Map(location=[52.51, 13.39], zoom_start=12)
folium_pane = pn.pane.plot.Folium(m, height=400)
folium_pane
Since folium maps are modified in place, changes to the map are only rendered once the object parameter is set again (or the update is triggered with folium_pane.param.trigger('object')):
folium.Marker(
[52.516, 13.381], popup="<i>Brandenburg Gate</i>", tooltip="Click me!"
).add_to(m)
folium_pane.object = m
The object may also be replaced entirely, e.g. to show a different location and tile layer:
folium_pane.object = folium.Map(location=[48.858, 2.294], zoom_start=15, tiles="CartoDB positron")
/Users/runner/work/panel/panel/.pixi/envs/docs/lib/python3.12/site-packages/folium/raster_layers.py:130: UserWarning: CartoDB tiles now require an API key. Please provide one to continue using the tiles. You can request the key at https://carto.com/basemaps/apikey/.
tiles = tiles.build_url(fill_subdomain=False, scale_factor="{r}") # type: ignore
Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).