Spaces:
Runtime error
Runtime error
import pandas as pd | |
import streamlit as st | |
from graphviz import Digraph | |
st.set_page_config(page_title="Ideal Care Plan for Top 10 Health Conditions") | |
# Create a pandas dataframe for the top 10 health conditions and their spending | |
health_conditions = [ | |
{"condition": "Heart disease ❤️", "spending": 214.3}, | |
{"condition": "Trauma-related disorders 🤕", "spending": 198.6}, | |
{"condition": "Cancer 🦀", "spending": 171.0}, | |
{"condition": "Mental disorders 🧠", "spending": 150.8}, | |
{"condition": "Osteoarthritis and joint disorders 🦴", "spending": 142.4}, | |
{"condition": "Diabetes 🍬", "spending": 107.4}, | |
{"condition": "Chronic obstructive pulmonary disease and asthma 🫁", "spending": 91.0}, | |
{"condition": "Hypertension 🩺", "spending": 83.9}, | |
{"condition": "Hyperlipidemia 🍔", "spending": 83.9}, | |
{"condition": "Back problems 👨⚕️", "spending": 67.0}, | |
] | |
df = pd.DataFrame(health_conditions) | |
# Create Graphviz graph object | |
graph = Digraph(comment="Ideal Care Plan for Top 10 Health Conditions") | |
graph.graph_attr["rankdir"] = "LR" # left to right layout | |
# Add nodes to the graph for each health condition | |
for i, row in df.iterrows(): | |
condition = row["condition"] | |
spending = row["spending"] | |
# Add node to the graph with hyperlink based on condition | |
if i < 3: | |
url = f"https://www.cdc.gov/{condition.split()[0].lower()}" | |
else: | |
url = None | |
graph.node(condition, f"{condition}\n${spending:.1f}B", href=url) | |
# Add edges to the graph based on related conditions | |
graph.edge("Heart disease ❤️", "Hypertension 🩺") | |
graph.edge("Heart disease ❤️", "Hyperlipidemia 🍔") | |
graph.edge("Trauma-related disorders 🤕", "Mental disorders 🧠") | |
graph.edge("Cancer 🦀", "Heart disease ❤️") | |
graph.edge("Cancer 🦀", "Trauma-related disorders 🤕") | |
graph.edge("Cancer 🦀", "Osteoarthritis and joint disorders 🦴") | |
graph.edge("Mental disorders 🧠", "Heart disease ❤️") | |
graph.edge("Mental disorders 🧠", "Trauma-related disorders 🤕") | |
graph.edge("Osteoarthritis and joint disorders 🦴", "Back problems 👨⚕️") | |
graph.edge("Diabetes 🍬", "Heart disease ❤️") | |
graph.edge("Diabetes 🍬", "Hypertension 🩺") | |
graph.edge("Chronic obstructive pulmonary disease and asthma 🫁", "Heart disease ❤️") | |
# Render the graph as an image and display in Streamlit app | |
st.graphviz_chart(graph.pipe(format="svg")) | |