Spaces:
Sleeping
Sleeping
pjgerrits
commited on
Commit
•
2b57c0b
1
Parent(s):
2b9fdf3
app updates
Browse files- app.py +52 -43
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
import psycopg2
|
3 |
import pandas as pd
|
4 |
-
import pydeck as pdk
|
5 |
|
6 |
st.set_page_config(layout="wide")
|
7 |
|
@@ -67,55 +69,62 @@ time_of_day = st.sidebar.selectbox("Time of Day", ["Morning", "Afternoon", "Even
|
|
67 |
day_of_week = st.sidebar.selectbox("Day of the Week", ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"])
|
68 |
description = st.sidebar.text_area("Why did you get lost?")
|
69 |
|
70 |
-
#
|
71 |
-
st.sidebar.title("Select Points on Map")
|
72 |
-
point_type = st.sidebar.radio("Select Point Type", ["start", "lost", "end"])
|
73 |
-
|
74 |
if 'points' not in st.session_state:
|
75 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
])
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
)
|
|
|
|
|
|
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
longitude=map_data['lon'].mean() if not map_data.empty else 0,
|
102 |
-
zoom=10,
|
103 |
-
pitch=0,
|
104 |
-
)
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
)
|
112 |
|
113 |
-
|
|
|
114 |
|
115 |
-
if st.button("Save"):
|
116 |
submit_data(age, gender, transport, multi_transport, time_of_day, day_of_week, description, st.session_state['points'])
|
117 |
|
118 |
-
st.markdown("---")
|
119 |
-
st.markdown("For a more detailed survey, click the link or scan the QR code:")
|
120 |
-
st.markdown("[https://arcg.is/1GK5jP0](https://arcg.is/1GK5jP0)")
|
121 |
-
st.image("static/Getting Lost Survey.png", width=200)
|
|
|
1 |
import streamlit as st
|
2 |
+
import folium
|
3 |
+
from streamlit_folium import st_folium
|
4 |
+
from folium.plugins import Draw, Geocoder, MiniMap
|
5 |
import psycopg2
|
6 |
import pandas as pd
|
|
|
7 |
|
8 |
st.set_page_config(layout="wide")
|
9 |
|
|
|
69 |
day_of_week = st.sidebar.selectbox("Day of the Week", ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"])
|
70 |
description = st.sidebar.text_area("Why did you get lost?")
|
71 |
|
72 |
+
# Initialize points in session state
|
|
|
|
|
|
|
73 |
if 'points' not in st.session_state:
|
74 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
75 |
|
76 |
+
# Map interaction
|
77 |
+
st.title("Select Points on the Map")
|
78 |
+
|
79 |
+
# Selector for point type
|
80 |
+
point_type = st.radio("Select Point Type to Add", ["start", "lost", "end"])
|
81 |
+
|
82 |
+
# Initialize map
|
83 |
+
m = folium.Map(location=[51.5074, -0.1278], zoom_start=10, control_scale=True)
|
84 |
+
|
85 |
+
# Add existing points to the map
|
86 |
+
for pointType, coords in st.session_state['points'].items():
|
87 |
+
if coords:
|
88 |
+
folium.Marker(
|
89 |
+
location=coords,
|
90 |
+
popup=pointType,
|
91 |
+
icon=folium.Icon(color="red" if pointType == "start" else "blue" if pointType == "end" else "orange")
|
92 |
+
).add_to(m)
|
93 |
+
|
94 |
+
# Add click functionality without creating popups
|
95 |
+
draw = Draw(
|
96 |
+
export=False,
|
97 |
+
draw_options={
|
98 |
+
"circle": False,
|
99 |
+
"polyline": False,
|
100 |
+
"polygon": False,
|
101 |
+
"rectangle": False,
|
102 |
+
"circlemarker": False,
|
103 |
+
"marker": True,
|
104 |
+
},
|
105 |
+
edit_options={"edit": False}
|
106 |
)
|
107 |
+
draw.add_to(m)
|
108 |
+
Geocoder(add_marker=True).add_to(m)
|
109 |
+
MiniMap().add_to(m)
|
110 |
|
111 |
+
# Display map
|
112 |
+
output = st_folium(m, width="100%", height=600, key="map")
|
|
|
|
|
|
|
|
|
113 |
|
114 |
+
# Check for map click data
|
115 |
+
if output and 'last_clicked' in output and output['last_clicked'] is not None:
|
116 |
+
lat = output['last_clicked']['lat']
|
117 |
+
lon = output['last_clicked']['lng']
|
118 |
+
st.session_state['points'][point_type] = (lat, lon)
|
119 |
+
st.experimental_rerun()
|
120 |
|
121 |
+
# Display current points
|
122 |
+
st.write("Current Points:", st.session_state['points'])
|
123 |
|
124 |
+
if st.sidebar.button("Save"):
|
125 |
submit_data(age, gender, transport, multi_transport, time_of_day, day_of_week, description, st.session_state['points'])
|
126 |
|
127 |
+
st.sidebar.markdown("---")
|
128 |
+
st.sidebar.markdown("For a more detailed survey, click the link or scan the QR code:")
|
129 |
+
st.sidebar.markdown("[https://arcg.is/1GK5jP0](https://arcg.is/1GK5jP0)")
|
130 |
+
st.sidebar.image("static/Getting Lost Survey.png", width=200)
|
requirements.txt
CHANGED
@@ -4,5 +4,6 @@
|
|
4 |
streamlit
|
5 |
psycopg2-binary
|
6 |
pandas
|
7 |
-
|
|
|
8 |
|
|
|
4 |
streamlit
|
5 |
psycopg2-binary
|
6 |
pandas
|
7 |
+
folium
|
8 |
+
streamlit_folium
|
9 |
|