Streamlit application that shows aggregated travel times in Madrid area. The app displays three different charts: a line chart, a map, and a bar chart.
NOTE: This project has been created with educational purposes
To create a multi-page application, we followed these steps:
- Create a new
pagesdirectory in the root folder to organize different pages - Create 3 different Python files inside
pages/for the 3 charts we want to show in different pages - Move the code for each chart to the corresponding Python file, importing necessary libraries and functions
- Create an
utils.pyfile to store common functions theread_and_preprocess_data()function, which is common to all pages - Remove all unnecessary code from the main
main.pyfile - Rename the chart pages using the following format:
1_📊_Chart1.py,2_🗺️_Chart2.py,3_📈_Chart3.py - Rename also the main page to
0_🏠_Home.py
To improve performance and user experience, we implemented a caching strategy using @cache_data. This decorator caches the function output based on its input arguments, so that the function is not re-executed if the input arguments are the same. In our case, we used it in the read_and_preprocess_data() function.
import streamlit as st
@st.cache_data
def read_and_preprocess_data():
# Data loading logic
passCreate a requirements.txt file with all necessary dependencies. You can use the pipreqs library to generate this file automatically.
pip install pipreqs
pipreqs /path/to/project- Create a GitHub repository for the project
- Push the code to the repository
- Log into Streamlit Cloud. You will need to associate your GitHub account with Streamlit.
- Create a new App in the Streamlit Platform
- Select the main file (
0_🏠_Home.py) as the app's entry point - Deploy the application