Skip to content

Instantly share code, notes, and snippets.

@ashhadulislam
Created February 12, 2022 12:02
Show Gist options
  • Save ashhadulislam/ecdc71f62752021140980d02e7f9cb18 to your computer and use it in GitHub Desktop.
Save ashhadulislam/ecdc71f62752021140980d02e7f9cb18 to your computer and use it in GitHub Desktop.
"""
This file is the framework for generating multiple Streamlit applications
through an object oriented framework.
"""
# Import necessary libraries
import streamlit as st
# Define the multipage class to manage the multiple apps in our program
class MultiPage:
"""Framework for combining multiple streamlit applications."""
def __init__(self) -> None:
"""Constructor class to generate a list which will store all our applications as an instance variable."""
self.pages = []
def add_page(self, title, func) -> None:
"""Class Method to Add pages to the project
Args:
title ([str]): The title of page which we are adding to the list of apps
func: Python function to render this page in Streamlit
"""
self.pages.append(
{
"title": title,
"function": func
}
)
def run(self):
# Drodown to select the page to run
page = st.sidebar.selectbox(
'App Navigation',
self.pages,
format_func=lambda page: page['title']
)
# run the app function
page['function']()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment