awacke1 commited on
Commit
969c70a
·
1 Parent(s): fca1033

Update app.py

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