-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmultipage_app.py
60 lines (52 loc) · 1.79 KB
/
multipage_app.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
from frontend_multipage_app import component_multipage_app
class MultiPage:
def __init__(self):
self.apps = []
self.app_names = []
def add_app(self, title, func, *args, **kwargs):
self.app_names.append(title)
self.apps.append({
"title": title,
"function": func,
"args":args,
"kwargs": kwargs
})
def run(self, label='Go To'):
def run_component(props):
value = component_multipage_app(key='multipage_app', **props)
return value
def handle_event(value):
# st.header('Streamlit')
# st.write('Received from component: ', value)
app_choice = value['choice']['state']['action'] if value else self.app_names[0]
app_choice_status = value['choice']['state']['value'] if value else False
if app_choice_status == True:
# run the selected app
app = self.apps[self.app_names.index(app_choice)]
app['function'](app['title'], *app['args'], **app['kwargs'])
else:
st.write('Awaiting selection')
props = {
'initial_state': {
'group_1_header': label
}
}
handle_event(run_component(props))
def app1(title, info=None):
st.title(title)
st.write(info)
def app2(title, info=None):
st.title(title)
st.write(info)
def app3(title, info=None):
st.title(title)
st.write(info)
def main():
mp = MultiPage()
mp.add_app('Application 1', app1, info='Hello from App 1')
mp.add_app('Application 2', app2, info='Hello from App 2')
mp.add_app('Application 3', app3, info='Hello from App 3')
mp.run('Launch Application')
if __name__ == '__main__':
main()