streamlit-folium integrates two great open-source projects in the Python ecosystem: Streamlit and Folium!
pip install streamlit-folium
or
conda install -c conda-forge streamlit-folium
Currently, there are two functions defined:
-
st_folium()
: a bi-directional Component, taking a Folium/Branca object and plotting to the Streamlit app. Upon mount/interaction with the Streamlit app,st_folium()
returns a Dict with selected information including the bounding box and items clicked on -
folium_static()
: takes afolium.Map
,folium.Figure
, orbranca.element.Figure
object and displays it in a Streamlit app.Note:
folium_static()
is based on the_repr_html()
representation created in Folium. This function should be a strict subset the of functionality of the newerst_folium()
function. It is recommended that users switch tost_folium()
as soon as possible, asfolium_static()
will likely be deprecated.If there is a reason why
folium_static()
needs to remain, please leave a GitHub issue describing your use case.
import streamlit as st
from streamlit_folium import folium_static
import folium
"# streamlit-folium"
with st.echo():
import streamlit as st
from streamlit_folium import folium_static
import folium
# center on Liberty Bell
m = folium.Map(location=[39.949610, -75.150282], zoom_start=16)
# add marker for Liberty Bell
tooltip = "Liberty Bell"
folium.Marker(
[39.949610, -75.150282], popup="Liberty Bell", tooltip=tooltip
).add_to(m)
# call to render Folium map in Streamlit
folium_static(m)