Spaces:
GIZ
/
Running on CPU Upgrade

SDSN-demo / appStore /multiapp.py
peter2000's picture
Update appStore/multiapp.py
446a8b4
raw
history blame
1.39 kB
"""Frameworks for running multiple Streamlit applications as a single app.
"""
import streamlit as st
from PIL import Image
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 = []
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.
"""
self.apps.append({
"title": title,
"function": func
})
def run(self):
st.sidebar.write(format_func=lambda app: app['title'])
image = Image.open('appStore/img/giz_sdsn.jpg')
st.sidebar.image(image)
app = st.sidebar.radio(
'Pages',
self.apps,
format_func=lambda app: app['title'])
app['function']()