Skip to content

dasirra/uber-demo-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uber Demo App

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

Project Evolution: From Single-page to Multi-page Application

1. Multi-page Structure Implementation

To create a multi-page application, we followed these steps:

  • Create a new pages directory 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.py file to store common functions the read_and_preprocess_data() function, which is common to all pages
  • Remove all unnecessary code from the main main.py file
  • 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

2. Implementing Streamlit Cache Mechanism

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.

Data Loading Optimization

import streamlit as st

@st.cache_data
def read_and_preprocess_data():
    # Data loading logic
    pass

3. Deployment to Streamlit Cloud

Prerequisites

Create 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

Deployment Steps

  1. Create a GitHub repository for the project
  2. Push the code to the repository
  3. Log into Streamlit Cloud. You will need to associate your GitHub account with Streamlit.
  4. Create a new App in the Streamlit Platform
  5. Select the main file (0_🏠_Home.py) as the app's entry point
  6. Deploy the application

About

This is the Uber Demo App for teaching

Resources

Stars

Watchers

Forks

Contributors

Languages