import folium import streamlit as st import pandas as pd from streamlit_folium import st_folium import time st.set_page_config(layout="wide") if not "sleep_time" in st.session_state: st.session_state.sleep_time = 2 if not "auto_refresh" in st.session_state: st.session_state.auto_refresh = True auto_refresh = st.sidebar.checkbox('Auto Refresh?', st.session_state.auto_refresh) if auto_refresh: number = st.sidebar.number_input('Refresh rate in seconds', value=st.session_state.sleep_time) st.session_state.sleep_time = number st.title("Streamlit Map Dashboard") st.subheader("Map with Folium in Streamlit") def parse_gg_sheet(url): url = url.replace('edit#gid=', 'export?format=csv&gid=') df = pd.read_csv(url) # parse latlng (column 4) to [lat, lng] def parse_latlng(latlng): if type(latlng) == str and ',' in latlng: lat, lng = latlng.split(',') return [float(lat), float(lng)] else: return None return df.assign(latlng=df.iloc[:, 4].apply(parse_latlng)) df = parse_gg_sheet("https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708") m = folium.Map(location=[31.628674, -7.992047], zoom_start=7.5) for index, row in df.iterrows(): if row['latlng'] is None: continue folium.Marker( location=row['latlng'], tooltip=row['العنوان أو اسم القرية'] if not pd.isna(row['العنوان أو اسم القرية']) else None, popup=row['رقم الهاتف (اختياري)'] if not pd.isna(row['رقم الهاتف (اختياري)']) else None, ).add_to(m) st_data = st_folium(m, use_container_width=True) if auto_refresh: time.sleep(number) st.experimental_rerun()