awacke1 commited on
Commit
0d3b956
·
1 Parent(s): 6cb3226

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -16
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
- # Define the states and conditions of interest
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
- # Total the spending values
23
- total_spending = sum([hc["spending"] for hc in health_conditions])
 
 
 
24
 
25
- # Create a DataFrame from the list dictionary
26
- df_top_conditions = pd.DataFrame(health_conditions)
 
 
27
 
28
- # Create the treemap graph using Plotly Express
29
- fig = px.treemap(df_top_conditions, path=["condition"], values="spending")
 
 
 
 
30
 
31
- # Set the title of the graph
32
- fig.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- # Display the graph in Streamlit
35
- st.plotly_chart(fig)
 
 
 
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"))