Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,36 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
|
|
3 |
|
4 |
-
|
|
|
|
|
5 |
|
|
|
6 |
health_conditions = [
|
7 |
-
{"condition": "Heart disease
|
8 |
-
{"condition": "Trauma-related disorders
|
9 |
-
{"condition": "Cancer
|
10 |
-
{"condition": "Mental disorders
|
11 |
-
{"condition": "Osteoarthritis and joint disorders
|
12 |
-
{"condition": "Diabetes
|
13 |
-
{"condition": "Chronic obstructive pulmonary disease and asthma
|
14 |
-
{"condition": "Hypertension
|
15 |
-
{"condition": "Hyperlipidemia
|
16 |
-
{"condition": "Back problems
|
17 |
]
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
"Trauma-related disorders 🤕": "https://www.nimh.nih.gov/health/topics/post-traumatic-stress-disorder-ptsd/index.shtml",
|
22 |
-
"Cancer 🦀": "https://www.cancer.gov/",
|
23 |
-
}
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
for condition in health_conditions:
|
28 |
-
name = condition["condition"]
|
29 |
-
spending = condition["spending"]
|
30 |
-
if name in urls:
|
31 |
-
url = urls[name]
|
32 |
-
dot.node(name, f"{name}\n${spending:.1f}B", href=url)
|
33 |
-
else:
|
34 |
-
dot.node(name, f"{name}\n${spending:.1f}B")
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
("Heart disease ❤️", "Hyperlipidemia 🍔"),
|
39 |
-
("Trauma-related disorders 🤕", "Mental disorders 🧠"),
|
40 |
-
("Cancer 🦀", "Heart disease ❤️"),
|
41 |
-
("Cancer 🦀", "Trauma-related disorders 🤕"),
|
42 |
-
("Cancer 🦀", "Osteoarthritis and joint disorders 🦴"),
|
43 |
-
("Mental disorders 🧠", "Heart disease ❤️"),
|
44 |
-
("Mental disorders 🧠", "Trauma-related disorders 🤕"),
|
45 |
-
("Osteoarthritis and joint disorders 🦴", "Back problems 👨⚕️"),
|
46 |
-
("Diabetes 🍬", "Heart disease ❤️"),
|
47 |
-
("Diabetes 🍬", "Hypertension 🩺"),
|
48 |
-
("Chronic obstructive pulmonary disease and asthma 🫁", "Heart disease ❤️"),
|
49 |
-
])
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import plotly.express as px
|
3 |
+
import pandas as pd
|
4 |
|
5 |
+
# Define the states and conditions of interest
|
6 |
+
states = ["Minnesota", "Florida", "California"]
|
7 |
+
top_n = 10
|
8 |
|
9 |
+
# Define the list dictionary of top 10 health conditions descending by cost
|
10 |
health_conditions = [
|
11 |
+
{"condition": "Heart disease", "spending": 214.3},
|
12 |
+
{"condition": "Trauma-related disorders", "spending": 198.6},
|
13 |
+
{"condition": "Cancer", "spending": 171.0},
|
14 |
+
{"condition": "Mental disorders", "spending": 150.8},
|
15 |
+
{"condition": "Osteoarthritis and joint disorders", "spending": 142.4},
|
16 |
+
{"condition": "Diabetes", "spending": 107.4},
|
17 |
+
{"condition": "Chronic obstructive pulmonary disease and asthma", "spending": 91.0},
|
18 |
+
{"condition": "Hypertension", "spending": 83.9},
|
19 |
+
{"condition": "Hyperlipidemia", "spending": 83.9},
|
20 |
+
{"condition": "Back problems", "spending": 67.0}
|
21 |
]
|
22 |
|
23 |
+
# Total the spending values
|
24 |
+
total_spending = sum([hc["spending"] for hc in health_conditions])
|
|
|
|
|
|
|
25 |
|
26 |
+
# Create a DataFrame from the list dictionary
|
27 |
+
df_top_conditions = pd.DataFrame(health_conditions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
# Create the treemap graph using Plotly Express
|
30 |
+
fig = px.treemap(df_top_conditions, path=["condition"], values="spending")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
# Set the title of the graph
|
33 |
+
fig.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
|
34 |
+
|
35 |
+
# Display the graph in Streamlit
|
36 |
+
st.plotly_chart(fig)
|