nouamanetazi HF staff commited on
Commit
b10dbaa
1 Parent(s): e696ed4
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import folium
2
+ import streamlit as st
3
+ import pandas as pd
4
+ from streamlit_folium import st_folium
5
+ import time
6
+ st.set_page_config(layout="wide")
7
+
8
+
9
+ if not "sleep_time" in st.session_state:
10
+ st.session_state.sleep_time = 2
11
+
12
+ if not "auto_refresh" in st.session_state:
13
+ st.session_state.auto_refresh = True
14
+
15
+ auto_refresh = st.sidebar.checkbox('Auto Refresh?', st.session_state.auto_refresh)
16
+
17
+ if auto_refresh:
18
+ number = st.sidebar.number_input('Refresh rate in seconds', value=st.session_state.sleep_time)
19
+ st.session_state.sleep_time = number
20
+
21
+ st.title("Streamlit Map Dashboard")
22
+ st.subheader("Map with Folium in Streamlit")
23
+
24
+ def parse_gg_sheet(url):
25
+ url = url.replace('edit#gid=', 'export?format=csv&gid=')
26
+ df = pd.read_csv(url)
27
+ # parse latlng (column 4) to [lat, lng]
28
+ def parse_latlng(latlng):
29
+ if type(latlng) == str and ',' in latlng:
30
+ lat, lng = latlng.split(',')
31
+ return [float(lat), float(lng)]
32
+ else:
33
+ return None
34
+ return df.assign(latlng=df.iloc[:, 4].apply(parse_latlng))
35
+ df = parse_gg_sheet("https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708")
36
+
37
+ m = folium.Map(location=[31.628674, -7.992047], zoom_start=7.5)
38
+
39
+ for index, row in df.iterrows():
40
+ if row['latlng'] is None:
41
+ continue
42
+ folium.Marker(
43
+ location=row['latlng'],
44
+ tooltip=row['العنوان أو اسم القرية'] if not pd.isna(row['العنوان أو اسم القرية']) else None,
45
+ popup=row['رقم الهاتف (اختياري)'] if not pd.isna(row['رقم الهاتف (اختياري)']) else None,
46
+ ).add_to(m)
47
+
48
+ st_data = st_folium(m, use_container_width=True)
49
+
50
+ if auto_refresh:
51
+ time.sleep(number)
52
+ st.experimental_rerun()