awacke1 commited on
Commit
fca1033
·
1 Parent(s): 4f6ea8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -42
app.py CHANGED
@@ -1,51 +1,36 @@
1
  import streamlit as st
2
- from graphviz import Digraph
 
3
 
4
- st.set_page_config(page_title="Ideal Care Plan for Top 10 Health Conditions")
 
 
5
 
 
6
  health_conditions = [
7
- {"condition": "Heart disease ❤️", "spending": 214.3},
8
- {"condition": "Trauma-related disorders 🤕", "spending": 198.6},
9
- {"condition": "Cancer 🦀", "spending": 171.0},
10
- {"condition": "Mental disorders 🧠", "spending": 150.8},
11
- {"condition": "Osteoarthritis and joint disorders 🦴", "spending": 142.4},
12
- {"condition": "Diabetes 🍬", "spending": 107.4},
13
- {"condition": "Chronic obstructive pulmonary disease and asthma 🫁", "spending": 91.0},
14
- {"condition": "Hypertension 🩺", "spending": 83.9},
15
- {"condition": "Hyperlipidemia 🍔", "spending": 83.9},
16
- {"condition": "Back problems 👨‍⚕️", "spending": 67.0},
17
  ]
18
 
19
- urls = {
20
- "Heart disease ❤️": "https://www.cdc.gov/heartdisease",
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
- dot = Digraph(comment="Ideal Care Plan for Top 10 Health Conditions")
26
- dot.graph_attr["rankdir"] = "LR"
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
- dot.edges([
37
- ("Heart disease ❤️", "Hypertension 🩺"),
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
- st.graphviz_chart(dot.pipe(format="svg"))
 
 
 
 
 
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)