-
Notifications
You must be signed in to change notification settings - Fork 2
/
multiapp.py
57 lines (51 loc) · 1.62 KB
/
multiapp.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
"""Frameworks for running multiple Streamlit applications as a single app.
"""
import streamlit as st
from st_on_hover_tabs import on_hover_tabs
class MultiApp:
"""Framework for combining multiple streamlit applications.
Usage:
def foo():
st.title("Hello Foo")
def bar():
st.title("Hello Bar")
app = MultiApp()
app.add_app("Foo", foo)
app.add_app("Bar", bar)
app.run()
It is also possible keep each application in a separate file.
import foo
import bar
app = MultiApp()
app.add_app("Foo", foo.app)
app.add_app("Bar", bar.app)
app.run()
"""
def __init__(self):
self.apps = None
def add_app(self, title, func):
"""Adds a new application.
Parameters
----------
func:
the python function to render this app.
title:
title of the app. Appears in the dropdown in the sidebar.
"""
if self.apps is None:
self.apps = []
self.apps.append({
"title": title,
"function": func
})
def run(self,df,st_state):
st.sidebar.header('Navigation')
titles = [app['title'] for app in self.apps]
app = st.sidebar.selectbox(
'Select an app:',
self.apps,
format_func=lambda app: app['title'],key='title')
st.sidebar.write('---')
app['function'](df,st_state)
#st.set_page_config(page_title='QSAR Modeling Web App',
# layout='wide')