Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,33 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def main():
|
6 |
st.title('State Comparison')
|
@@ -24,33 +51,21 @@ def main():
|
|
24 |
writer.writeheader()
|
25 |
for state in state_list:
|
26 |
writer.writerow(state)
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
# Create a map with pie charts for each state
|
32 |
-
m = folium.Map(location=[37.0902, -95.7129], zoom_start=4)
|
33 |
|
|
|
|
|
34 |
for state, data in state_data.items():
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
st.
|
45 |
-
|
46 |
-
def get_coordinates(state):
|
47 |
-
# Replace this with your own function to get the coordinates for each state
|
48 |
-
# This is just a placeholder
|
49 |
-
return np.random.randint(-120, -70), np.random.randint(25, 50)
|
50 |
-
|
51 |
-
def create_pie_chart(data, labels, colors):
|
52 |
-
chart = folium.plugins.PieChart(data, labels=labels, colors=colors, radius=30, weight=0.5)
|
53 |
-
return chart
|
54 |
-
|
55 |
-
def folium_map_to_html(m):
|
56 |
-
return m.get_root().render()
|
|
|
1 |
import streamlit as st
|
2 |
+
import csv
|
3 |
+
import base64
|
4 |
+
|
5 |
+
# Define the state populations and family sizes
|
6 |
+
state_data = {
|
7 |
+
'California': {'population': 39538223, 'family_size': 3.3},
|
8 |
+
'Texas': {'population': 29145505, 'family_size': 3.4},
|
9 |
+
'Florida': {'population': 21538187, 'family_size': 3.0},
|
10 |
+
'New York': {'population': 19849399, 'family_size': 3.1},
|
11 |
+
'Minnesota': {'population': 5700671, 'family_size': 2.5},
|
12 |
+
'Wisconsin': {'population': 5897473, 'family_size': 2.6},
|
13 |
+
}
|
14 |
+
|
15 |
+
# Define the state spending data
|
16 |
+
spending_data = {
|
17 |
+
'California': {'education': 2500, 'healthcare': 3000, 'transportation': 1500},
|
18 |
+
'Texas': {'education': 2000, 'healthcare': 2500, 'transportation': 1000},
|
19 |
+
'Florida': {'education': 1500, 'healthcare': 2000, 'transportation': 750},
|
20 |
+
'New York': {'education': 3000, 'healthcare': 3500, 'transportation': 2000},
|
21 |
+
'Minnesota': {'education': 1000, 'healthcare': 1500, 'transportation': 500},
|
22 |
+
'Wisconsin': {'education': 1250, 'healthcare': 1750, 'transportation': 750},
|
23 |
+
}
|
24 |
+
|
25 |
+
# Define the emoji icons
|
26 |
+
POPULATION_ICON = 'π₯'
|
27 |
+
FAMILY_SIZE_ICON = 'π¨βπ©βπ§βπ¦'
|
28 |
+
EDUCATION_ICON = 'π«'
|
29 |
+
HEALTHCARE_ICON = 'π₯'
|
30 |
+
TRANSPORTATION_ICON = 'π'
|
31 |
|
32 |
def main():
|
33 |
st.title('State Comparison')
|
|
|
51 |
writer.writeheader()
|
52 |
for state in state_list:
|
53 |
writer.writerow(state)
|
54 |
+
with open('state_data.csv', mode='rb') as file:
|
55 |
+
b64 = base64.b64encode(file.read()).decode('utf-8')
|
56 |
+
st.markdown(f'<a href="data:file/csv;base64,{b64}" download="state_data.csv">Download State Data CSV File</a>', unsafe_allow_html=True)
|
|
|
|
|
|
|
57 |
|
58 |
+
# Display state populations and family sizes
|
59 |
+
st.header('Population and Family Size')
|
60 |
for state, data in state_data.items():
|
61 |
+
st.subheader(f'{POPULATION_ICON} {state}')
|
62 |
+
st.write(f'Population: {data["population"]}')
|
63 |
+
st.write(f'Family Size: {data["family_size"]}')
|
64 |
+
|
65 |
+
# Display state spending data
|
66 |
+
st.header('State Spending')
|
67 |
+
for state, data in spending_data.items():
|
68 |
+
st.subheader(state)
|
69 |
+
st.write(f'{EDUCATION_ICON} Education: {data["education"]}')
|
70 |
+
st.write(f'{HEALTHCARE_ICON} Healthcare: {data["healthcare"]}')
|
71 |
+
st.write(f'{TRANSPORTATION_ICON} Transportation: {data["transportation"]}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|