Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import plotly.express as px
|
3 |
import pandas as pd
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
states = ["Minnesota 🌲", "Florida 🌴", "California 🌞"]
|
7 |
-
top_n = 10
|
8 |
|
|
|
9 |
health_conditions = [
|
10 |
{"condition": "Heart disease ❤️", "spending": 214.3},
|
11 |
{"condition": "Trauma-related disorders 🤕", "spending": 198.6},
|
@@ -16,20 +15,40 @@ health_conditions = [
|
|
16 |
{"condition": "Chronic obstructive pulmonary disease and asthma 🫁", "spending": 91.0},
|
17 |
{"condition": "Hypertension 🩺", "spending": 83.9},
|
18 |
{"condition": "Hyperlipidemia 🍔", "spending": 83.9},
|
19 |
-
{"condition": "Back problems 👨⚕️", "spending": 67.0}
|
20 |
]
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
#
|
26 |
-
|
|
|
|
|
27 |
|
28 |
-
#
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
#
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
#
|
35 |
-
st.
|
|
|
|
|
|
|
1 |
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
from graphviz import Digraph
|
4 |
|
5 |
+
st.set_page_config(page_title="Ideal Care Plan for Top 10 Health Conditions")
|
|
|
|
|
6 |
|
7 |
+
# Create a pandas dataframe for the top 10 health conditions and their spending
|
8 |
health_conditions = [
|
9 |
{"condition": "Heart disease ❤️", "spending": 214.3},
|
10 |
{"condition": "Trauma-related disorders 🤕", "spending": 198.6},
|
|
|
15 |
{"condition": "Chronic obstructive pulmonary disease and asthma 🫁", "spending": 91.0},
|
16 |
{"condition": "Hypertension 🩺", "spending": 83.9},
|
17 |
{"condition": "Hyperlipidemia 🍔", "spending": 83.9},
|
18 |
+
{"condition": "Back problems 👨⚕️", "spending": 67.0},
|
19 |
]
|
20 |
|
21 |
+
df = pd.DataFrame(health_conditions)
|
22 |
+
|
23 |
+
# Create Graphviz graph object
|
24 |
+
graph = Digraph(comment="Ideal Care Plan for Top 10 Health Conditions")
|
25 |
+
graph.graph_attr["rankdir"] = "LR" # left to right layout
|
26 |
|
27 |
+
# Add nodes to the graph for each health condition
|
28 |
+
for i, row in df.iterrows():
|
29 |
+
condition = row["condition"]
|
30 |
+
spending = row["spending"]
|
31 |
|
32 |
+
# Add node to the graph with hyperlink based on condition
|
33 |
+
if i < 3:
|
34 |
+
url = f"https://www.cdc.gov/{condition.split()[0].lower()}"
|
35 |
+
else:
|
36 |
+
url = None
|
37 |
+
graph.node(condition, f"{condition}\n${spending:.1f}B", href=url)
|
38 |
|
39 |
+
# Add edges to the graph based on related conditions
|
40 |
+
graph.edge("Heart disease ❤️", "Hypertension 🩺")
|
41 |
+
graph.edge("Heart disease ❤️", "Hyperlipidemia 🍔")
|
42 |
+
graph.edge("Trauma-related disorders 🤕", "Mental disorders 🧠")
|
43 |
+
graph.edge("Cancer 🦀", "Heart disease ❤️")
|
44 |
+
graph.edge("Cancer 🦀", "Trauma-related disorders 🤕")
|
45 |
+
graph.edge("Cancer 🦀", "Osteoarthritis and joint disorders 🦴")
|
46 |
+
graph.edge("Mental disorders 🧠", "Heart disease ❤️")
|
47 |
+
graph.edge("Mental disorders 🧠", "Trauma-related disorders 🤕")
|
48 |
+
graph.edge("Osteoarthritis and joint disorders 🦴", "Back problems 👨⚕️")
|
49 |
+
graph.edge("Diabetes 🍬", "Heart disease ❤️")
|
50 |
+
graph.edge("Diabetes 🍬", "Hypertension 🩺")
|
51 |
+
graph.edge("Chronic obstructive pulmonary disease and asthma 🫁", "Heart disease ❤️")
|
52 |
|
53 |
+
# Render the graph as an image and display in Streamlit app
|
54 |
+
st.graphviz_chart(graph.pipe(format="svg"))
|