awacke1's picture
Update app.py
c693514
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)