awacke1 commited on
Commit
ead695a
Β·
1 Parent(s): 5145d36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -43
app.py CHANGED
@@ -1,33 +1,6 @@
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')
@@ -55,18 +28,29 @@ def main():
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"]}')
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import folium
3
+ import numpy as np
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def main():
6
  st.title('State Comparison')
 
28
  b64 = base64.b64encode(file.read()).decode('utf-8')
29
  st.markdown(f'<a href="data:file/csv;base64,{b64}" download="state_data.csv">Download State Data CSV File</a>', unsafe_allow_html=True)
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
+ lat, lon = get_coordinates(state)
36
+ popup_text = f'<b>{state}</b><br>Population: {data["population"]}<br>Family Size: {data["family_size"]}'
37
+ chart_data = [spending_data[state]['education'], spending_data[state]['healthcare'], spending_data[state]['transportation']]
38
+ chart_labels = ['Education', 'Healthcare', 'Transportation']
39
+ colors = ['blue', 'red', 'green']
40
+ chart = create_pie_chart(chart_data, chart_labels, colors)
41
+ folium.Marker(location=[lat, lon], popup=popup_text, icon=folium.Icon(color='gray', icon='info-sign')).add_to(m)
42
+ folium.Marker(location=[lat, lon], icon=folium.Icon(color='cadetblue', icon='chart-pie'), tooltip='Click for chart').add_to(m).add_child(chart)
43
+
44
+ st.markdown(folium_map_to_html(m), unsafe_allow_html=True)
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()