awacke1 commited on
Commit
8a61a98
Β·
1 Parent(s): 16f32ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -54
app.py CHANGED
@@ -1,58 +1,14 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import random
4
- import plotly.graph_objects as go
5
- import plotly.express as px
6
-
7
- # Define the states and conditions of interest
8
- states = ["Minnesota", "Florida", "California"]
9
- top_n = 10
10
-
11
- # Define the list dictionary of top 10 health conditions descending by cost, with emojis
12
- health_conditions = [
13
- {"condition": "πŸ’” Heart disease", "emoji": "πŸ’—", "spending": 214.3},
14
- {"condition": "πŸ€• Trauma-related disorders", "emoji": "πŸš‘", "spending": 198.6},
15
- {"condition": "πŸ¦€ Cancer", "emoji": "πŸŽ—οΈ", "spending": 171.0},
16
- {"condition": "🧠 Mental disorders", "emoji": "🧘", "spending": 150.8},
17
- {"condition": "🦴 Osteoarthritis and joint disorders", "emoji": "πŸ₯", "spending": 142.4},
18
- {"condition": "πŸ’‰ Diabetes", "emoji": "🩸", "spending": 107.4},
19
- {"condition": "🫁 Chronic obstructive pulmonary disease and asthma", "emoji": "πŸ«€", "spending": 91.0},
20
- {"condition": "🩺 Hypertension", "emoji": "πŸ’‰", "spending": 83.9},
21
- {"condition": "πŸ”¬ Hyperlipidemia", "emoji": "πŸ”¬", "spending": 83.9},
22
- {"condition": "🦴 Back problems", "emoji": "🧍", "spending": 67.0}
23
- ]
24
-
25
- # Create a DataFrame from the list dictionary
26
  df_top_conditions = pd.DataFrame(health_conditions)
27
-
28
- # Calculate the total spending
29
  total_spending = round(df_top_conditions["spending"].sum(), 1)
30
-
31
- # Define the reroll function
32
- def reroll():
33
- # Randomly select a health condition from the top 10
34
- index = random.randint(0, 9)
35
- condition = df_top_conditions.loc[index, "condition"]
36
- emoji = df_top_conditions.loc[index, "emoji"]
37
- spending = df_top_conditions.loc[index, "spending"]
38
- # Print the condition and ask the user if they want to reroll
39
- st.write(f"You rolled: {emoji} {condition} (spending: ${spending}B)")
40
- reroll = st.button("Reroll")
41
- # If the user clicks the reroll button, call the reroll function again
42
- if reroll:
43
- reroll()
44
-
45
- # Define the sunburst chart
46
- fig_sunburst = go.Figure(go.Sunburst(
47
- labels=df_top_conditions["emoji"] + " " + df_top_conditions["condition"],
48
- parents=[""] * top_n,
49
- values=df_top_conditions["spending"],
50
- maxdepth=2
51
- ))
52
-
53
- # Customize the layout of the sunburst chart
54
  fig_sunburst.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
55
-
56
- # Display the sunburst chart and reroll button in the Streamlit app
57
  st.plotly_chart(fig_sunburst)
58
- st.button("Reroll", on_click=reroll)
 
 
 
 
 
1
+ import streamlit as st, pandas as pd, random, plotly.graph_objects as go, plotly.express as px
2
+ states, top_n = ["Minnesota", "Florida", "California"], 10
3
+ 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}]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  df_top_conditions = pd.DataFrame(health_conditions)
 
 
5
  total_spending = round(df_top_conditions["spending"].sum(), 1)
6
+ def roll(): return [random.randint(1, 10) for _ in range(1000)]
7
+ fig_sunburst = go.Figure(go.Sunburst(labels=df_top_conditions["emoji"] + " " + df_top_conditions["condition"], parents=[""] * top_n, values=df_top_conditions["spending"], maxdepth=2))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  fig_sunburst.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
 
 
9
  st.plotly_chart(fig_sunburst)
10
+ for index, row in df_top_conditions.iterrows():
11
+ frequencies = roll()
12
+ fig_bar = px.bar(x=[f"Variant {i}" for i in range(1, 11)], y=frequencies, labels={'x': 'Variant', 'y': 'Frequency'})
13
+ fig_bar.update_layout(title=f"Variants of {row['condition']} ({row['emoji']})")
14
+ st.plotly_chart(fig_bar)