Spaces:
Sleeping
Sleeping
New app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
# Install plotly if not already installed
|
| 6 |
+
try:
|
| 7 |
+
import plotly
|
| 8 |
+
except ImportError:
|
| 9 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "plotly"])
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# import subprocess
|
| 13 |
+
# import sys
|
| 14 |
+
|
| 15 |
+
import pandas as pd
|
| 16 |
+
import streamlit as st
|
| 17 |
+
import plotly.express as px
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# Load Dataset
|
| 22 |
+
# Example: 'country' column for country names, other columns for years
|
| 23 |
+
data = pd.read_csv("child_mortality_0_5_year_olds_dying_per_1000_born.csv")
|
| 24 |
+
|
| 25 |
+
# Melt the data to long format for easier filtering
|
| 26 |
+
data_melted = data.melt(id_vars=["country"], var_name="year", value_name="mortality_rate")
|
| 27 |
+
data_melted["year"] = pd.to_numeric(data_melted["year"])
|
| 28 |
+
|
| 29 |
+
# Streamlit App
|
| 30 |
+
st.title("Global Child Mortality Rate (per 1000 children born)")
|
| 31 |
+
st.write("""This interactive visualization provides an insightful overview of child mortality rates (number of deaths per 1,000 live births) across countries for a selected year.
|
| 32 |
+
The data highlights disparities in healthcare, socioeconomic conditions, and development across the globe, making it a valuable tool for understanding global health challenges.""")
|
| 33 |
+
|
| 34 |
+
# Add year selection
|
| 35 |
+
# years = sorted(data_melted["year"].unique()) # Extract unique years from the dataset
|
| 36 |
+
# selected_year = st.selectbox("Select Year", years)
|
| 37 |
+
# Add year selection with a slider
|
| 38 |
+
min_year = int(data_melted["year"].min())
|
| 39 |
+
max_year = int(data_melted["year"].max())
|
| 40 |
+
|
| 41 |
+
st.subheader("Child Mortality Trends around the Globe")
|
| 42 |
+
st.write("""
|
| 43 |
+
This Chart reveals an important trend of how the child mortality rate have been changing across the years.
|
| 44 |
+
This gives us a very important insight on how the present developed countries have successfully reduced the rate, and underdeveloped countries still faces challenges to curb child mortality successfully.
|
| 45 |
+
We can utilise the trends in the graph to understand the factors which might be the responsible for high mortality or low mortality.
|
| 46 |
+
This will help the policymakers in developing/under-developed countries to develop data-driven policy to reduce child mortality.
|
| 47 |
+
""")
|
| 48 |
+
|
| 49 |
+
selected_year = st.slider("Select Year", min_value=min_year, max_value=max_year, value = 2024, step = 5)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# Filter data for the selected year
|
| 53 |
+
filtered_data = data_melted[data_melted["year"] == selected_year]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# Create the map
|
| 57 |
+
fig = px.choropleth(
|
| 58 |
+
filtered_data,
|
| 59 |
+
locations="country", # Country names or ISO 3166-1 Alpha-3 codes
|
| 60 |
+
locationmode="country names", # Use 'ISO-3' if you have country codes
|
| 61 |
+
color="mortality_rate",
|
| 62 |
+
title=f"Child Mortality Rate in {selected_year}",
|
| 63 |
+
color_continuous_scale=px.colors.sequential.OrRd, # Customize the color scale
|
| 64 |
+
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# Display the map
|
| 68 |
+
st.plotly_chart(fig)
|