nouamanetazi HF staff commited on
Commit
01defef
1 Parent(s): 380bb23

add refresh

Browse files
Files changed (1) hide show
  1. app.py +39 -15
app.py CHANGED
@@ -3,50 +3,74 @@ 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()
 
3
  import pandas as pd
4
  from streamlit_folium import st_folium
5
  import time
 
6
 
7
+ st.set_page_config(layout="wide")
8
 
9
+ if "sleep_time" not in st.session_state:
10
  st.session_state.sleep_time = 2
11
 
12
+ if "auto_refresh" not 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("Nt3awnu نتعاونو")
22
+
23
+ # you can report more data here: https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708
24
+ # description
25
+ st.markdown("Help us report more people in need by filling this form: https://forms.gle/nZNCUVog9ka2Vdqu6")
26
+
27
 
28
  def parse_gg_sheet(url):
29
+ url = url.replace("edit#gid=", "export?format=csv&gid=")
30
  df = pd.read_csv(url)
31
+
32
  # parse latlng (column 4) to [lat, lng]
33
  def parse_latlng(latlng):
34
+ if type(latlng) == str and "," in latlng:
35
+ lat, lng = latlng.split(",")
36
  return [float(lat), float(lng)]
37
  else:
38
  return None
39
+
40
  return df.assign(latlng=df.iloc[:, 4].apply(parse_latlng))
41
+
42
+
43
+ df = parse_gg_sheet(
44
+ "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
45
+ )
46
 
47
  m = folium.Map(location=[31.628674, -7.992047], zoom_start=7.5)
48
 
49
  for index, row in df.iterrows():
50
+ if row["latlng"] is None:
51
  continue
52
  folium.Marker(
53
+ location=row["latlng"],
54
+ tooltip=row["العنوان أو اسم القرية"] if not pd.isna(row["العنوان أو اسم القرية"]) else None,
55
+ popup=row["رقم الهاتف (اختياري)"] if not pd.isna(row["رقم الهاتف (اختياري)"]) else None,
56
  ).add_to(m)
57
 
58
  st_data = st_folium(m, use_container_width=True)
59
 
60
+ st.markdown(
61
+ """
62
+ <iframe src="https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/" width="100%" height="600px"></iframe>
63
+ """,
64
+ unsafe_allow_html=True,
65
+ )
66
+
67
+ # st.markdown(
68
+ # """
69
+ # <iframe src="https://docs.google.com/forms/d/e/1FAIpQLSfNrFHUScot5jQyRUJmor7kWYgwkkME6WqRgQG_L4Eze4RdHA/viewform?embedded=true" width="640" height="2877" frameborder="0" marginheight="0" marginwidth="0">Loading…</iframe>
70
+ # """,
71
+ # unsafe_allow_html=True,
72
+ # )
73
+
74
  if auto_refresh:
75
  time.sleep(number)
76
  st.experimental_rerun()