I have the following code in folium that allows you to select a point in the map and plots a circle at this point. However the circle is not displayed directly and requires to do a second action to display it, such as zoom out or click on another location. I would like to not have that and the circle plotting to directly come after the click. I now it is extremely simple but I haven’t figured out how to fix this.
Can someone help please? Thank you
import folium
import streamlit as st
from streamlit_folium import st_folium
def main():
m = folium.Map(location=[0, 0], zoom_start=1)
folium.LatLngPopup().add_to(m)
fg = folium.FeatureGroup(name="circle")
if 'lat, lon, radius' not in st.session_state:
st.session_state['lat, lon, radius'] = None
if st.session_state['lat, lon, radius'] is not None:
print(st.session_state['lat, lon, radius'])
child = folium.Circle(radius=10**st.session_state['lat, lon, radius'][-1], location=st.session_state['lat, lon, radius'][:2], color='#ff7800', fill=True, fill_color='#ffff00', fill_opacity=0.2)
fg.add_child(child)
radius = st.slider("Radius", 1, 7, step=1)
gps = st_folium(m, width=1000, feature_group_to_add=fg)
if gps.get('last_clicked') is not None:
lat, lon = gps['last_clicked']['lat'], gps['last_clicked']['lng']
st.session_state['lat, lon, radius'] = lat, lon, radius
st.write('Location/Radius', gps['last_clicked']['lat'], gps['last_clicked']['lng'], radius)
if __name__ == "__main__":
main()