Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,56 +1,48 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import folium
|
| 3 |
from streamlit_folium import folium_static
|
| 4 |
-
import
|
| 5 |
-
import random
|
| 6 |
|
| 7 |
# Define hospitals data for Minnesota
|
| 8 |
-
hospitals =
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Create a map centered on Minnesota
|
| 15 |
m = folium.Map(location=[45.0, -94.0], zoom_start=7)
|
| 16 |
|
| 17 |
# Add markers for each hospital
|
| 18 |
-
for hospital in
|
| 19 |
folium.Marker(
|
| 20 |
-
location=[hospital[
|
| 21 |
-
popup=f'{hospital[
|
| 22 |
icon=folium.Icon(color='red')
|
| 23 |
).add_to(m)
|
| 24 |
|
| 25 |
# Add waypoints for each hospital
|
| 26 |
-
waypoints = [(hospital[
|
| 27 |
folium.plugins.AntPath(waypoints, delay=3000).add_to(m)
|
| 28 |
|
| 29 |
# Function to update the map when a button is clicked
|
| 30 |
def update_map(hospital_data):
|
| 31 |
-
m.location = [hospital_data[
|
| 32 |
m.zoom_start = 13
|
| 33 |
folium_static(m)
|
| 34 |
|
| 35 |
# Create a grid of buttons for selecting hospitals
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
if st.button(hospitals[1][0]):
|
| 42 |
-
update_map(hospitals[1])
|
| 43 |
-
with col3:
|
| 44 |
-
if st.button(hospitals[2][0]):
|
| 45 |
-
update_map(hospitals[2])
|
| 46 |
-
|
| 47 |
-
col4, col5, col6 = st.columns(3)
|
| 48 |
-
with col4:
|
| 49 |
-
if st.button(hospitals[3][0]):
|
| 50 |
-
update_map(hospitals[3])
|
| 51 |
-
with col5:
|
| 52 |
-
if st.button(hospitals[4][0]):
|
| 53 |
-
update_map(hospitals[4])
|
| 54 |
|
| 55 |
# Display the map in Streamlit
|
| 56 |
folium_static(m)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import folium
|
| 3 |
from streamlit_folium import folium_static
|
| 4 |
+
import pandas as pd
|
|
|
|
| 5 |
|
| 6 |
# Define hospitals data for Minnesota
|
| 7 |
+
hospitals = pd.DataFrame({
|
| 8 |
+
'name': ['Mayo Clinic', 'University of Minnesota Medical Center', 'Hennepin County Medical Center',
|
| 9 |
+
'Regions Hospital', 'Abbott Northwestern Hospital'],
|
| 10 |
+
'city': ['Rochester', 'Minneapolis', 'Minneapolis', 'St. Paul', 'Minneapolis'],
|
| 11 |
+
'lat': [44.023678, 44.971389, 44.972078, 44.942936, 44.955447],
|
| 12 |
+
'lon': [-92.466955, -93.240556, -93.261769, -93.093457, -93.268543],
|
| 13 |
+
'beds': [1368, 1002, 484, 454, 640]
|
| 14 |
+
})
|
| 15 |
+
|
| 16 |
+
# Sort hospitals by number of beds and select the top ten
|
| 17 |
+
top_hospitals = hospitals.sort_values('beds', ascending=False).head(10)
|
| 18 |
|
| 19 |
# Create a map centered on Minnesota
|
| 20 |
m = folium.Map(location=[45.0, -94.0], zoom_start=7)
|
| 21 |
|
| 22 |
# Add markers for each hospital
|
| 23 |
+
for i, hospital in top_hospitals.iterrows():
|
| 24 |
folium.Marker(
|
| 25 |
+
location=[hospital['lat'], hospital['lon']],
|
| 26 |
+
popup=f"{hospital['name']}<br>{hospital['city']}<br>{hospital['beds']} beds",
|
| 27 |
icon=folium.Icon(color='red')
|
| 28 |
).add_to(m)
|
| 29 |
|
| 30 |
# Add waypoints for each hospital
|
| 31 |
+
waypoints = [(hospital['lat'], hospital['lon']) for i, hospital in top_hospitals.iterrows()]
|
| 32 |
folium.plugins.AntPath(waypoints, delay=3000).add_to(m)
|
| 33 |
|
| 34 |
# Function to update the map when a button is clicked
|
| 35 |
def update_map(hospital_data):
|
| 36 |
+
m.location = [hospital_data['lat'], hospital_data['lon']]
|
| 37 |
m.zoom_start = 13
|
| 38 |
folium_static(m)
|
| 39 |
|
| 40 |
# Create a grid of buttons for selecting hospitals
|
| 41 |
+
cols = st.columns(5)
|
| 42 |
+
for i, hospital in top_hospitals.iterrows():
|
| 43 |
+
with cols[i % 5]:
|
| 44 |
+
if st.button(hospital['name']):
|
| 45 |
+
update_map(hospital)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Display the map in Streamlit
|
| 48 |
folium_static(m)
|