shanroy1999 commited on
Commit
43a5bb0
·
verified ·
1 Parent(s): 2e2780d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +25 -20
src/streamlit_app.py CHANGED
@@ -14,7 +14,7 @@ st.set_page_config(
14
  initial_sidebar_state="expanded"
15
  )
16
 
17
- # --- 2. Sidebar for Metadata (Rubric: Data is linked) ---
18
  with st.sidebar:
19
  st.header("About This Project")
20
  st.markdown("**Authors:**")
@@ -32,18 +32,18 @@ with st.sidebar:
32
  st.markdown("[IMF Banking Crises](https://www.imf.org/en/Publications/WP/Issues/2018/09/14/Systemic-Banking-Crises-Revisited-46232)")
33
  st.info("This dashboard visualizes how the 2008 financial crisis propagated from the US to the rest of the world.")
34
 
35
- # --- 3. Main Title (Rubric: Compelling Title included) ---
36
  st.title("📉 The Domino Effect: How the 2008 Crisis Went Global")
37
  st.markdown("---")
38
 
39
- # --- 4. Connective Text Part 1 (Rubric: Write up - Paragraph 1) ---
40
  st.markdown("""
41
  ### 🌍 When Wall Street Sneezed, the World Caught a Cold
42
  In 2008, what started as a burst housing bubble in the United States quickly mutated into a global economic catastrophe. But how does a problem in one country infect the entire world? The answer lies in **Financial Contagion**.
43
 
44
  Just like a virus moving through a crowded room, economic shockwaves travel through international connections. In our modern economy, nations are linked by **Trade** (buying and selling goods) and **Finance** (banks lending money across borders). When the US economy collapsed, it stopped buying goods from China and Germany, and US banks pulled money out of emerging markets like Brazil.
45
 
46
- In this data story, we will explore these connections. We will see how "open" economies—those that trade the most—often paid the highest price during the panic, and how the "cure" (government bailouts) created a new disease: massive public debt.
47
  """)
48
 
49
  # --- 5. Data Loading (Cached) ---
@@ -53,7 +53,8 @@ def load_wdi_data():
53
  indicators = {
54
  'GDP_Growth': 'NY.GDP.MKTP.KD.ZG',
55
  'Trade_GDP': 'NE.TRD.GNFS.ZS',
56
- 'Gov_Debt': 'GC.DOD.TOTL.GD.ZS',
 
57
  'Youth_Unemployment': 'SL.UEM.1524.ZS',
58
  'Total_Unemployment': 'SL.UEM.TOTL.ZS'
59
  }
@@ -88,7 +89,7 @@ def load_wdi_data():
88
  with st.spinner("Fetching data from World Bank..."):
89
  df = load_wdi_data()
90
 
91
- # --- 6. Central Interactive Visualization (Rubric: Interactive, Large, Friendly) ---
92
  st.header("📊 The Crash in Motion (2000-2020)")
93
  st.markdown("""
94
  **How to read this chart:** * **X-Axis:** Represents how "open" an economy is (Trade as % of GDP).
@@ -124,34 +125,38 @@ fig_main.add_hline(y=0, line_dash="dash", line_color="red", annotation_text="Rec
124
  st.plotly_chart(fig_main, use_container_width=True)
125
  st.caption("Source: World Bank World Development Indicators (WDI). Size of bubble represents trade openness.")
126
 
127
- # --- 7. Connective Text Part 2 (Rubric: Write up - Paragraph 2) ---
128
  st.markdown("""
129
- ### 💸 The Cost of Bailouts: Private Failure, Public Debt
130
  The immediate crash was stopped, but at a high cost. When major banks failed in 2008, governments stepped in to save them with massive "bailouts"—using taxpayer money to prevent the financial system from collapsing.
131
 
132
- This created a massive transfer of debt. What was originally **private debt** (held by banks) became **public debt** (held by the government). As the chart below shows, countries like the United States and United Kingdom saw their central government debt explode after 2008. This debt burden forced many nations into "austerity" measures, cutting public services to pay back creditors.
133
  """)
134
 
135
- # --- 8. Contextual Viz 1 (Rubric: Contextual Viz included & Cited) ---
136
  debt_countries = ['United States', 'United Kingdom', 'Japan', 'Greece', 'Germany']
137
- df_debt = df[df['Country Name'].isin(debt_countries)]
 
 
 
138
 
139
  fig_debt = px.line(
140
  df_debt,
141
  x="Year",
142
- y="Gov_Debt",
143
  color="Country Name",
144
- title="Contextual Viz 1: The Debt Explosion (2000-2020)",
145
- labels={"Gov_Debt": "Central Gov. Debt (% of GDP)"},
146
  markers=True,
147
  template="plotly_white"
148
  )
149
- fig_debt.add_vline(x=2008, line_dash="dot", line_color="black", annotation_text="Crisis Starts")
 
150
 
151
  st.plotly_chart(fig_debt, use_container_width=True)
152
- st.caption("Source: World Bank WDI. Note the sharp upward trend starting exactly in 2008 for Western economies.")
153
 
154
- # --- 9. Connective Text Part 3 (Rubric: Write up - Paragraph 3) ---
155
  st.markdown("""
156
  ### 🎓 The Lost Generation
157
  While stock markets eventually recovered, the human cost of the crisis lingered for years. In Europe specifically, the financial crisis mutated into a sovereign debt crisis, leading to a long-term depression in the labor market.
@@ -159,7 +164,7 @@ While stock markets eventually recovered, the human cost of the crisis lingered
159
  The group hit hardest was young adults (ages 15-24). In countries like Spain and Greece, youth unemployment skyrocketed to over **50%**. This created a "Lost Generation" of workers who were locked out of the job market during their most critical skill-building years. The comparison below highlights how disproportionately youth were affected compared to the general population during the peak of the crisis.
160
  """)
161
 
162
- # --- 10. Contextual Viz 2 (Rubric: Contextual Viz included & Cited) ---
163
  # Snapshot of 2013 (Peak Euro Crisis)
164
  df_2013 = df[df['Year'] == 2013]
165
  focus_countries = ['Spain', 'Greece', 'Italy', 'Portugal', 'Germany', 'United States']
@@ -193,10 +198,10 @@ fig_youth = px.bar(
193
  st.plotly_chart(fig_youth, use_container_width=True)
194
  st.caption("Source: World Bank WDI. Data represents the peak of the Eurozone crisis in 2013.")
195
 
196
- # --- 11. Final Citations (Rubric: Citations included) ---
197
  st.markdown("---")
198
  st.markdown("### 📚 References")
199
  st.markdown("""
200
- 1. **World Bank World Development Indicators (WDI):** The primary source for GDP, Trade, Debt, and Unemployment data. [Link to Dataset](https://databank.worldbank.org/source/world-development-indicators)
201
  2. **IMF Systemic Banking Crises Database:** Used for identifying crisis timelines. Laeven, L., & Valencia, F. (2018). [Link to Paper](https://www.imf.org/en/Publications/WP/Issues/2018/09/14/Systemic-Banking-Crises-Revisited-46232)
202
  """)
 
14
  initial_sidebar_state="expanded"
15
  )
16
 
17
+ # --- 2. Sidebar for Metadata ---
18
  with st.sidebar:
19
  st.header("About This Project")
20
  st.markdown("**Authors:**")
 
32
  st.markdown("[IMF Banking Crises](https://www.imf.org/en/Publications/WP/Issues/2018/09/14/Systemic-Banking-Crises-Revisited-46232)")
33
  st.info("This dashboard visualizes how the 2008 financial crisis propagated from the US to the rest of the world.")
34
 
35
+ # --- 3. Main Title ---
36
  st.title("📉 The Domino Effect: How the 2008 Crisis Went Global")
37
  st.markdown("---")
38
 
39
+ # --- 4. Connective Text Part 1 ---
40
  st.markdown("""
41
  ### 🌍 When Wall Street Sneezed, the World Caught a Cold
42
  In 2008, what started as a burst housing bubble in the United States quickly mutated into a global economic catastrophe. But how does a problem in one country infect the entire world? The answer lies in **Financial Contagion**.
43
 
44
  Just like a virus moving through a crowded room, economic shockwaves travel through international connections. In our modern economy, nations are linked by **Trade** (buying and selling goods) and **Finance** (banks lending money across borders). When the US economy collapsed, it stopped buying goods from China and Germany, and US banks pulled money out of emerging markets like Brazil.
45
 
46
+ In this data story, we will explore these connections. We will see how "open" economies—those that trade the most—often paid the highest price during the panic, and how the "cure" (government bailouts) created a new disease: massive public deficits.
47
  """)
48
 
49
  # --- 5. Data Loading (Cached) ---
 
53
  indicators = {
54
  'GDP_Growth': 'NY.GDP.MKTP.KD.ZG',
55
  'Trade_GDP': 'NE.TRD.GNFS.ZS',
56
+ # Switched to Deficit because Debt stock data is sparse for Japan/Germany in API
57
+ 'Gov_Deficit': 'GC.BAL.CASH.GD.ZS',
58
  'Youth_Unemployment': 'SL.UEM.1524.ZS',
59
  'Total_Unemployment': 'SL.UEM.TOTL.ZS'
60
  }
 
89
  with st.spinner("Fetching data from World Bank..."):
90
  df = load_wdi_data()
91
 
92
+ # --- 6. Central Interactive Visualization ---
93
  st.header("📊 The Crash in Motion (2000-2020)")
94
  st.markdown("""
95
  **How to read this chart:** * **X-Axis:** Represents how "open" an economy is (Trade as % of GDP).
 
125
  st.plotly_chart(fig_main, use_container_width=True)
126
  st.caption("Source: World Bank World Development Indicators (WDI). Size of bubble represents trade openness.")
127
 
128
+ # --- 7. Connective Text Part 2 ---
129
  st.markdown("""
130
+ ### 💸 The Cost of Bailouts: Massive Deficits
131
  The immediate crash was stopped, but at a high cost. When major banks failed in 2008, governments stepped in to save them with massive "bailouts"—using taxpayer money to prevent the financial system from collapsing.
132
 
133
+ This created massive **budget deficits**. As the chart below shows, governments like the United States, UK, and Greece spent far more than they earned in 2009 (indicated by the deep plunge into negative territory). This sudden spending shock laid the groundwork for the Sovereign Debt Crisis that followed.
134
  """)
135
 
136
+ # --- 8. Contextual Viz 1: Deficits (Better Data Coverage) ---
137
  debt_countries = ['United States', 'United Kingdom', 'Japan', 'Greece', 'Germany']
138
+ df_debt = df[df['Country Name'].isin(debt_countries)].copy()
139
+
140
+ # Fix: Drop NaN values specifically for this plot so lines connect properly
141
+ df_debt = df_debt.dropna(subset=['Gov_Deficit'])
142
 
143
  fig_debt = px.line(
144
  df_debt,
145
  x="Year",
146
+ y="Gov_Deficit",
147
  color="Country Name",
148
+ title="Contextual Viz 1: The Cost of Bailouts - Budget Surplus/Deficit (% of GDP)",
149
+ labels={"Gov_Deficit": "Surplus/Deficit (% of GDP)"},
150
  markers=True,
151
  template="plotly_white"
152
  )
153
+ fig_debt.add_vline(x=2009, line_dash="dot", line_color="red", annotation_text="Peak Bailout Spending")
154
+ fig_debt.add_hline(y=0, line_color="black", line_width=1) # Zero line for balance
155
 
156
  st.plotly_chart(fig_debt, use_container_width=True)
157
+ st.caption("Source: World Bank WDI. Negative values indicate a government deficit (spending more than earning). Note the synchronized crash in 2009.")
158
 
159
+ # --- 9. Connective Text Part 3 ---
160
  st.markdown("""
161
  ### 🎓 The Lost Generation
162
  While stock markets eventually recovered, the human cost of the crisis lingered for years. In Europe specifically, the financial crisis mutated into a sovereign debt crisis, leading to a long-term depression in the labor market.
 
164
  The group hit hardest was young adults (ages 15-24). In countries like Spain and Greece, youth unemployment skyrocketed to over **50%**. This created a "Lost Generation" of workers who were locked out of the job market during their most critical skill-building years. The comparison below highlights how disproportionately youth were affected compared to the general population during the peak of the crisis.
165
  """)
166
 
167
+ # --- 10. Contextual Viz 2: The Lost Generation ---
168
  # Snapshot of 2013 (Peak Euro Crisis)
169
  df_2013 = df[df['Year'] == 2013]
170
  focus_countries = ['Spain', 'Greece', 'Italy', 'Portugal', 'Germany', 'United States']
 
198
  st.plotly_chart(fig_youth, use_container_width=True)
199
  st.caption("Source: World Bank WDI. Data represents the peak of the Eurozone crisis in 2013.")
200
 
201
+ # --- 11. Final Citations ---
202
  st.markdown("---")
203
  st.markdown("### 📚 References")
204
  st.markdown("""
205
+ 1. **World Bank World Development Indicators (WDI):** The primary source for GDP, Trade, Deficits, and Unemployment data. [Link to Dataset](https://databank.worldbank.org/source/world-development-indicators)
206
  2. **IMF Systemic Banking Crises Database:** Used for identifying crisis timelines. Laeven, L., & Valencia, F. (2018). [Link to Paper](https://www.imf.org/en/Publications/WP/Issues/2018/09/14/Systemic-Banking-Crises-Revisited-46232)
207
  """)