Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,64 +2,124 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import altair as alt
|
4 |
|
5 |
-
#
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
#
|
9 |
-
largest_hospitals_df =
|
10 |
-
|
11 |
-
# Select columns to display
|
12 |
-
cols_to_display = ["State", "Hospital Name", "City", "Zip Code", "lat", "lng"]
|
13 |
-
|
14 |
-
# Create a Streamlit table to display the largest hospitals
|
15 |
-
st.table(largest_hospitals_df[cols_to_display])
|
16 |
|
17 |
# Define chart functions
|
18 |
-
def
|
19 |
-
chart = alt.Chart(largest_hospitals_df).
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
width=700,
|
26 |
-
height=400,
|
27 |
-
title='Number of Hospitals by State and Type'
|
28 |
-
)
|
29 |
-
text = chart.mark_text(
|
30 |
-
align='center',
|
31 |
-
baseline='middle',
|
32 |
-
dx=0,
|
33 |
-
dy=5,
|
34 |
-
color='white'
|
35 |
-
).encode(
|
36 |
-
text=alt.Text('count():Q', format='.1f')
|
37 |
-
)
|
38 |
-
st.altair_chart(chart + text)
|
39 |
-
|
40 |
-
def bump_chart():
|
41 |
-
chart = alt.Chart(largest_hospitals_df).transform_rank(
|
42 |
-
'Hospital overall rating',
|
43 |
-
groupby=['State']
|
44 |
-
).mark_line().encode(
|
45 |
-
x='rank:Q',
|
46 |
-
y=alt.Y('Hospital Name:N', sort='-x'),
|
47 |
-
color=alt.Color('State:N'),
|
48 |
-
tooltip=['City', 'Zip Code', 'Hospital overall rating']
|
49 |
).properties(
|
50 |
width=700,
|
51 |
-
height=
|
52 |
-
title='
|
53 |
)
|
54 |
st.altair_chart(chart)
|
55 |
|
56 |
# Define chart buttons
|
57 |
st.sidebar.header('Select a Chart')
|
58 |
-
chart_options = ['
|
59 |
chart_choice = st.sidebar.selectbox('', chart_options)
|
60 |
|
61 |
# Call chart functions based on user input
|
62 |
-
if chart_choice == '
|
63 |
-
|
64 |
-
|
65 |
-
bump_chart()
|
|
|
2 |
import pandas as pd
|
3 |
import altair as alt
|
4 |
|
5 |
+
# Define list of largest hospitals with latitude and longitude
|
6 |
+
largest_hospitals = [
|
7 |
+
{
|
8 |
+
'name': 'Florida Hospital Orlando',
|
9 |
+
'city': 'Orlando',
|
10 |
+
'state': 'FL',
|
11 |
+
'zip_code': '32803',
|
12 |
+
'bed_count': 2411,
|
13 |
+
'lat': 28.562229,
|
14 |
+
'lng': -81.362976
|
15 |
+
},
|
16 |
+
{
|
17 |
+
'name': 'Cleveland Clinic',
|
18 |
+
'city': 'Cleveland',
|
19 |
+
'state': 'OH',
|
20 |
+
'zip_code': '44195',
|
21 |
+
'bed_count': 1730,
|
22 |
+
'lat': 41.501669,
|
23 |
+
'lng': -81.621275
|
24 |
+
},
|
25 |
+
{
|
26 |
+
'name': 'Mayo Clinic',
|
27 |
+
'city': 'Rochester',
|
28 |
+
'state': 'MN',
|
29 |
+
'zip_code': '55905',
|
30 |
+
'bed_count': 1372,
|
31 |
+
'lat': 44.020634,
|
32 |
+
'lng': -92.463476
|
33 |
+
},
|
34 |
+
{
|
35 |
+
'name': 'NewYork-Presbyterian Hospital-Columbia and Cornell',
|
36 |
+
'city': 'New York',
|
37 |
+
'state': 'NY',
|
38 |
+
'zip_code': '10032',
|
39 |
+
'bed_count': 2332,
|
40 |
+
'lat': 40.840886,
|
41 |
+
'lng': -73.942184
|
42 |
+
},
|
43 |
+
{
|
44 |
+
'name': 'UCHealth University of Colorado Hospital',
|
45 |
+
'city': 'Aurora',
|
46 |
+
'state': 'CO',
|
47 |
+
'zip_code': '80045',
|
48 |
+
'bed_count': 672,
|
49 |
+
'lat': 39.742401,
|
50 |
+
'lng': -104.834694
|
51 |
+
},
|
52 |
+
{
|
53 |
+
'name': 'Houston Methodist Hospital',
|
54 |
+
'city': 'Houston',
|
55 |
+
'state': 'TX',
|
56 |
+
'zip_code': '77030',
|
57 |
+
'bed_count': 1063,
|
58 |
+
'lat': 29.710292,
|
59 |
+
'lng': -95.399262
|
60 |
+
},
|
61 |
+
{
|
62 |
+
'name': 'Johns Hopkins Hospital',
|
63 |
+
'city': 'Baltimore',
|
64 |
+
'state': 'MD',
|
65 |
+
'zip_code': '21287',
|
66 |
+
'bed_count': 1293,
|
67 |
+
'lat': 39.297082,
|
68 |
+
'lng': -76.590726
|
69 |
+
},
|
70 |
+
{
|
71 |
+
'name': 'Massachusetts General Hospital',
|
72 |
+
'city': 'Boston',
|
73 |
+
'state': 'MA',
|
74 |
+
'zip_code': '02114',
|
75 |
+
'bed_count': 1032,
|
76 |
+
'lat': 42.363371,
|
77 |
+
'lng': -71.068635
|
78 |
+
},
|
79 |
+
{
|
80 |
+
'name': 'University of Michigan Hospitals-Michigan Medicine',
|
81 |
+
'city': 'Ann Arbor',
|
82 |
+
'state': 'MI',
|
83 |
+
'zip_code': '48109',
|
84 |
+
'bed_count': 1145,
|
85 |
+
'lat': 42.282531,
|
86 |
+
'lng': -83.728376
|
87 |
+
},
|
88 |
+
{
|
89 |
+
'name': 'Mount Sinai Hospital',
|
90 |
+
'city': 'New York',
|
91 |
+
'state': 'NY',
|
92 |
+
'zip_code': '10029',
|
93 |
+
'bed_count': 1168,
|
94 |
+
'lat': 40.789866,
|
95 |
+
'lng': -73.952348
|
96 |
+
}
|
97 |
+
]
|
98 |
|
99 |
+
# Convert list of largest hospitals to a Pandas DataFrame
|
100 |
+
largest_hospitals_df = pd.DataFrame(largest_hospitals)
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
# Define chart functions
|
103 |
+
def map_chart():
|
104 |
+
chart = alt.Chart(largest_hospitals_df).mark_circle().encode(
|
105 |
+
longitude='lng:Q',
|
106 |
+
latitude='lat:Q',
|
107 |
+
size=alt.Size('bed_count:Q', title='Bed Count'),
|
108 |
+
color=alt.Color('state:N', legend=alt.Legend(title='State')),
|
109 |
+
tooltip=['name', 'bed_count', 'city', 'state']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
).properties(
|
111 |
width=700,
|
112 |
+
height=500,
|
113 |
+
title='Location of Largest Hospitals in the US'
|
114 |
)
|
115 |
st.altair_chart(chart)
|
116 |
|
117 |
# Define chart buttons
|
118 |
st.sidebar.header('Select a Chart')
|
119 |
+
chart_options = ['Map Chart']
|
120 |
chart_choice = st.sidebar.selectbox('', chart_options)
|
121 |
|
122 |
# Call chart functions based on user input
|
123 |
+
if chart_choice == 'Map Chart':
|
124 |
+
map_chart()
|
125 |
+
|
|