Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import random
|
4 |
+
import plotly.graph_objects as go
|
5 |
+
import plotly.express as px
|
6 |
+
|
7 |
+
# Define the states and conditions of interest
|
8 |
+
states = ["Minnesota", "Florida", "California"]
|
9 |
+
top_n = 10
|
10 |
+
|
11 |
+
# Define the list dictionary of top 10 health conditions descending by cost, with emojis
|
12 |
+
health_conditions = [
|
13 |
+
{"condition": "๐ Heart disease", "emoji": "๐", "spending": 214.3},
|
14 |
+
{"condition": "๐ค Trauma-related disorders", "emoji": "๐", "spending": 198.6},
|
15 |
+
{"condition": "๐ฆ Cancer", "emoji": "๐๏ธ", "spending": 171.0},
|
16 |
+
{"condition": "๐ง Mental disorders", "emoji": "๐ง", "spending": 150.8},
|
17 |
+
{"condition": "๐ฆด Osteoarthritis and joint disorders", "emoji": "๐ฅ", "spending": 142.4},
|
18 |
+
{"condition": "๐ Diabetes", "emoji": "๐ฉธ", "spending": 107.4},
|
19 |
+
{"condition": "๐ซ Chronic obstructive pulmonary disease and asthma", "emoji": "๐ซ", "spending": 91.0},
|
20 |
+
{"condition": "๐ฉบ Hypertension", "emoji": "๐", "spending": 83.9},
|
21 |
+
{"condition": "๐ฌ Hyperlipidemia", "emoji": "๐ฌ", "spending": 83.9},
|
22 |
+
{"condition": "๐ฆด Back problems", "emoji": "๐ง", "spending": 67.0}
|
23 |
+
]
|
24 |
+
|
25 |
+
# Create a DataFrame from the list dictionary
|
26 |
+
df_top_conditions = pd.DataFrame(health_conditions)
|
27 |
+
|
28 |
+
# Define the reroll function
|
29 |
+
def reroll():
|
30 |
+
# Randomly select a health condition from the top 10
|
31 |
+
index = random.randint(0, 9)
|
32 |
+
condition = df_top_conditions.loc[index, "condition"]
|
33 |
+
emoji = df_top_conditions.loc[index, "emoji"]
|
34 |
+
spending = df_top_conditions.loc[index, "spending"]
|
35 |
+
# Print the condition and ask the user if they want to reroll
|
36 |
+
st.write(f"You rolled: {emoji} {condition} (spending: ${spending}B)")
|
37 |
+
reroll = st.button("Reroll")
|
38 |
+
# If the user clicks the reroll button, call the reroll function again
|
39 |
+
if reroll:
|
40 |
+
reroll()
|
41 |
+
|
42 |
+
# Create the map graph using Plotly Express
|
43 |
+
fig_map = px.choropleth(locations=["CA", "FL", "MN"], locationmode="USA-states", color=[1, 2, 3], scope="usa")
|
44 |
+
fig_map.update_layout(geo=dict(bgcolor= "rgba(0, 0, 0, 0)", lakecolor="rgb(255, 255, 255)"))
|
45 |
+
|
46 |
+
# Create the bar chart using Plotly Graph Objects
|
47 |
+
fig_bar = go.Figure(go.Bar(x=df_top_conditions["emoji"] + " " + df_top_conditions["condition"], y=df_top_conditions["spending"], marker_color="#1f77b4"))
|
48 |
+
fig_bar.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)",
|
49 |
+
yaxis_title="Spending ($B)", plot_bgcolor='rgba(0,0
|