Skip to content

Commit

Permalink
Add callbacks demo
Browse files Browse the repository at this point in the history
  • Loading branch information
blackary committed Jan 7, 2025
1 parent 7e41158 commit af06272
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/pages/callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import streamlit as st

st.set_page_config(
page_title="streamlit-folium documentation",
page_icon=":world_map:️",
layout="wide",
)


"# Callbacks"

"""
Try moving the map and zooming in and out and see the callback in action.
"""

with st.echo():
import folium
import streamlit as st

from streamlit_folium import st_folium

# center on Liberty Bell, add marker
m = folium.Map(location=[39.949610, -75.150282], zoom_start=16)
folium.Marker(
[39.949610, -75.150282], popup="Liberty Bell", tooltip="Liberty Bell"
).add_to(m)

def callback():
st.toast(f"Current zoom: {st.session_state['my_map']['zoom']}")
st.toast(f"Current center: {st.session_state['my_map']['center']}")

# call to render Folium map in Streamlit
st_data = st_folium(m, width=725, key="my_map", on_change=callback)

0 comments on commit af06272

Please sign in to comment.