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)