Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -73,5 +73,55 @@ def app():
|
|
73 |
file.write(f'Tip' + ': {tip} {emoji}\nLife points: 10\n')
|
74 |
st.success('Tip submitted!')
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
if __name__ == '__main__':
|
77 |
app()
|
|
|
|
|
|
|
|
73 |
file.write(f'Tip' + ': {tip} {emoji}\nLife points: 10\n')
|
74 |
st.success('Tip submitted!')
|
75 |
|
76 |
+
|
77 |
+
import streamlit as st
|
78 |
+
import pandas as pd
|
79 |
+
import plotly.graph_objects as go
|
80 |
+
import plotly.express as px
|
81 |
+
|
82 |
+
# Define the states and conditions of interest
|
83 |
+
states = ["Minnesota", "Florida", "California", "Washington", "Maine", "Texas"]
|
84 |
+
top_n = 10
|
85 |
+
|
86 |
+
# Define the list dictionary of top 10 health conditions descending by cost, with emojis
|
87 |
+
health_conditions = [
|
88 |
+
{"condition": "๐ Heart disease", "emoji": "๐", "spending": 214.3},
|
89 |
+
{"condition": "๐ค Trauma-related disorders", "emoji": "๐", "spending": 198.6},
|
90 |
+
{"condition": "๐ฆ Cancer", "emoji": "๐๏ธ", "spending": 171.0},
|
91 |
+
{"condition": "๐ง Mental disorders", "emoji": "๐ง", "spending": 150.8},
|
92 |
+
{"condition": "๐ฆด Osteoarthritis and joint disorders", "emoji": "๐ฅ", "spending": 142.4},
|
93 |
+
{"condition": "๐ Diabetes", "emoji": "๐ฉธ", "spending": 107.4},
|
94 |
+
{"condition": "๐ซ Chronic obstructive pulmonary disease and asthma", "emoji": "๐ซ", "spending": 91.0},
|
95 |
+
{"condition": "๐ฉบ Hypertension", "emoji": "๐", "spending": 83.9},
|
96 |
+
{"condition": "๐ฌ Hyperlipidemia", "emoji": "๐ฌ", "spending": 83.9},
|
97 |
+
{"condition": "๐ฆด Back problems", "emoji": "๐ง", "spending": 67.0}
|
98 |
+
]
|
99 |
+
|
100 |
+
# Total the spending values
|
101 |
+
total_spending = sum([hc["spending"] for hc in health_conditions])
|
102 |
+
|
103 |
+
# Create a DataFrame from the list dictionary
|
104 |
+
df_top_conditions = pd.DataFrame(health_conditions)
|
105 |
+
|
106 |
+
# Create the map graph using Plotly Express
|
107 |
+
locations = ["CA", "FL", "MN", "WA", "ME", "TX"]
|
108 |
+
fig_map = px.choropleth(locations=locations, locationmode="USA-states", color=[1, 2, 3, 4, 5, 6], scope="usa")
|
109 |
+
fig_map.update_layout(geo=dict(bgcolor= "rgba(0, 0, 0, 0)", lakecolor="rgb(255, 255, 255)"))
|
110 |
+
|
111 |
+
# Create the bar chart using Plotly Graph Objects
|
112 |
+
fig_bar = go.Figure(go.Bar(x=df_top_conditions["emoji"] + " " + df_top_conditions["condition"], y=df_top_conditions["spending"], marker_color="#1f77b4"))
|
113 |
+
fig_bar.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)",
|
114 |
+
yaxis_title="Spending ($B)", plot_bgcolor='rgba(0,0,0,0)', xaxis=dict(showgrid=False), yaxis=dict(showgrid=False))
|
115 |
+
|
116 |
+
# Display the map and the bar chart in Streamlit
|
117 |
+
col1, col2 = st.columns([2, 1])
|
118 |
+
with col1:
|
119 |
+
st.plotly_chart(fig_map, use_container_width=True)
|
120 |
+
with col2:
|
121 |
+
st.plotly_chart(fig_bar, use_container_width=True)
|
122 |
+
|
123 |
if __name__ == '__main__':
|
124 |
app()
|
125 |
+
|
126 |
+
|
127 |
+
|