fp3 / app.py
SmeetPatel's picture
Update app.py
a6ea37f verified
raw
history blame
2.74 kB
import os
import subprocess
import sys
# Install plotly if not already installed
try:
import plotly
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", "plotly"])
# import subprocess
# import sys
import pandas as pd
import streamlit as st
import plotly.express as px
# Load Dataset
# Example: 'country' column for country names, other columns for years
data = pd.read_csv("https://huggingface.co/spaces/jiyachachan/fp2/resolve/main/child_mortality_0_5_year_olds_dying_per_1000_born.csv")
# Melt the data to long format for easier filtering
data_melted = data.melt(id_vars=["country"], var_name="year", value_name="mortality_rate")
data_melted["year"] = pd.to_numeric(data_melted["year"])
# Streamlit App
st.title("Global Child Mortality Rate (per 1000 children born)")
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.
The data highlights disparities in healthcare, socioeconomic conditions, and development across the globe, making it a valuable tool for understanding global health challenges.""")
# Add year selection
# years = sorted(data_melted["year"].unique()) # Extract unique years from the dataset
# selected_year = st.selectbox("Select Year", years)
# Add year selection with a slider
min_year = int(data_melted["year"].min())
max_year = int(data_melted["year"].max())
st.subheader("Child Mortality Trends around the Globe")
st.write("""
This Chart reveals an important trend of how the child mortality rate have been changing across the years.
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.
We can utilise the trends in the graph to understand the factors which might be the responsible for high mortality or low mortality.
This will help the policymakers in developing/under-developed countries to develop data-driven policy to reduce child mortality.
""")
selected_year = st.slider("Select Year", min_value=min_year, max_value=max_year, value = 2024, step = 5)
# Filter data for the selected year
filtered_data = data_melted[data_melted["year"] == selected_year]
# Create the map
fig = px.choropleth(
filtered_data,
locations="country", # Country names or ISO 3166-1 Alpha-3 codes
locationmode="country names", # Use 'ISO-3' if you have country codes
color="mortality_rate",
title=f"Child Mortality Rate in {selected_year}",
color_continuous_scale=px.colors.sequential.OrRd, # Customize the color scale
)
# Display the map
st.plotly_chart(fig)