-
Notifications
You must be signed in to change notification settings - Fork 0
/
multipage.py
46 lines (38 loc) · 1.35 KB
/
multipage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""This module defines the multipage object used by streamlit frontend"""
from typing import Any, Callable
import streamlit as st
# Define the multipage class to manage the multiple apps in our program
class Multipage:
"""
Framework for combining multiple streamlit apps
"""
def __init__(self) -> None:
self.pages = dict()
def add_page(self, title: str, func: Callable,
args: tuple[Any, ...] | None = None,
kwargs: dict[Any] | None = None) -> None:
"""
This module adds the page to the main app.
Args:
title (str): Title of the page
func (Callable): Function that renders the app
args: Arguments that are supplied to the function func
kwargs: Keyword arguments supplied to the function func
"""
if args is None:
args = tuple()
if kwargs is None:
kwargs = dict()
self.pages[title] = {
'function': func,
'args': args,
'kwargs': kwargs,
}
def run(self):
"""This method handles page navigation"""
current_page = st.sidebar.selectbox(
'Go to page:',
self.pages.keys(),
)
current_app = self.pages[current_page]
current_app['function'](*current_app['args'], **current_app['kwargs'])