Spaces:
Runtime error
Runtime error
File size: 2,277 Bytes
0d3b956 fca1033 969c70a a3a53d2 fca1033 a3a53d2 969c70a e3887ab 969c70a e3887ab fca1033 4f6ea8d fca1033 4f6ea8d 969c70a 4f6ea8d 969c70a fca1033 969c70a c693514 969c70a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import streamlit as st
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
# Define the states and conditions of interest
states = ["Minnesota", "Florida", "California"]
top_n = 10
# Define the list dictionary of top 10 health conditions descending by cost, with emojis
health_conditions = [
{"condition": "💔 Heart disease", "emoji": "💗", "spending": 214.3},
{"condition": "🤕 Trauma-related disorders", "emoji": "🚑", "spending": 198.6},
{"condition": "🦀 Cancer", "emoji": "🎗️", "spending": 171.0},
{"condition": "🧠 Mental disorders", "emoji": "🧘", "spending": 150.8},
{"condition": "🦴 Osteoarthritis and joint disorders", "emoji": "🏥", "spending": 142.4},
{"condition": "💉 Diabetes", "emoji": "🩸", "spending": 107.4},
{"condition": "🫁 Chronic obstructive pulmonary disease and asthma", "emoji": "🫀", "spending": 91.0},
{"condition": "🩺 Hypertension", "emoji": "💉", "spending": 83.9},
{"condition": "🔬 Hyperlipidemia", "emoji": "🔬", "spending": 83.9},
{"condition": "🦴 Back problems", "emoji": "🧍", "spending": 67.0}
]
# Total the spending values
total_spending = sum([hc["spending"] for hc in health_conditions])
# Create a DataFrame from the list dictionary
df_top_conditions = pd.DataFrame(health_conditions)
# Create the map graph using Plotly Express
fig_map = px.choropleth(locations=["CA", "FL", "MN"], locationmode="USA-states", color=[1, 2, 3], scope="usa")
fig_map.update_layout(geo=dict(bgcolor= "rgba(0, 0, 0, 0)", lakecolor="rgb(255, 255, 255)"))
# Create the bar chart using Plotly Graph Objects
fig_bar = go.Figure(go.Bar(x=df_top_conditions["emoji"] + " " + df_top_conditions["condition"], y=df_top_conditions["spending"], marker_color="#1f77b4"))
fig_bar.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)",
yaxis_title="Spending ($B)", plot_bgcolor='rgba(0,0,0,0)', xaxis=dict(showgrid=False), yaxis=dict(showgrid=False))
# Display the map and the bar chart in Streamlit
col1, col2 = st.columns([2, 1])
with col1:
st.plotly_chart(fig_map, use_container_width=True)
with col2:
st.plotly_chart(fig_bar, use_container_width=True)
|