j-sauceda
Initial commit
0e559de
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 26 15:04:49 2023
@author: jorge
"""
# StreamLit gapminder demo dashboard in 50 lines
# based on https://towardsdatascience.com/building-a-dashboard-in-under-5-minutes-with-streamlit-fd0c906ff886
import streamlit as st
import plotly.express as px
# Create three columns
# First and third columns are dummy to add a space to the sides
col1, col2, col3 = st.columns([5, 20, 5])
# Second column could host a streamlit image
# Commented image downloaded
with col2:
st.title("Streamlit Demo")
# Get the user input
year_col, continent_col, log_x_col = st.columns([5, 5, 5])
with year_col:
year_choice = st.slider( # select year slider
"What year would you like to examine?",
min_value=1952,
max_value=2007,
step=5,
value=2007,
)
with continent_col:
continent_choice = st.selectbox( # select continent box
"What continent would you like to look at?",
("All", "Asia", "Europe", "Africa", "Americas", "Oceania"),
)
with log_x_col: # log-scale check box
log_x_choice = st.checkbox("Log X Axis?")
# Load the gapminder data frame
df = px.data.gapminder()
# Apply the year filter given by the user
filtered_df = df[(df.year == year_choice)]
# Apply the continent filter
if continent_choice != "All":
filtered_df = filtered_df[filtered_df.continent == continent_choice]
# Create the figure in Plotly
fig = px.scatter(
filtered_df,
x="gdpPercap",
y="lifeExp",
size="pop",
color="continent",
hover_name="country",
log_x=log_x_choice,
size_max=60,
)
fig.update_layout(title="GDP per Capita vs. Life Expectancy")
# Associate Plotly chart to the Streamlit interface
st.plotly_chart(fig, use_container_width=True)