From af0627200ca2192cd709a2b25890235cd52d0c0c Mon Sep 17 00:00:00 2001 From: Zachary Blackwood Date: Tue, 7 Jan 2025 14:21:44 -0500 Subject: [PATCH] Add callbacks demo --- examples/pages/callbacks.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/pages/callbacks.py diff --git a/examples/pages/callbacks.py b/examples/pages/callbacks.py new file mode 100644 index 0000000..c6977b6 --- /dev/null +++ b/examples/pages/callbacks.py @@ -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)