Skip to content

Instantly share code, notes, and snippets.

@alanjones2
Created June 2, 2022 10:39
Show Gist options
  • Save alanjones2/5475581669644c2e0d3c7adc4765ed5c to your computer and use it in GitHub Desktop.
Save alanjones2/5475581669644c2e0d3c7adc4765ed5c to your computer and use it in GitHub Desktop.
02-06-22-stmulitpage-mp4.py
message = """
__Select an application from the list below__
"""
import json
import streamlit as st
import importlib
import stlib # default library name for apps
from stlib import libContents
st.set_page_config(layout = "wide") # optional
st.header("National Statistics")
# Global arrays for holding the app names, modules
# and descriptions of the apps
moduleNames = libContents.packages()
descriptions = []
modules = []
# Find the apps and import them
for modname in moduleNames:
m = importlib.import_module('.'+modname,'stlib')
modules.append(m)
# If the module has a description attribute use that in the
# select box otherwise use the module name
try:
descriptions.append(m.description)
except:
descriptions.append(modname)
# Define a function to display the app
# descriptions instead of the module names
# in the selctbox, below
def format_func(name):
return descriptions[moduleNames.index(name)]
# Display the sidebar with a menu of apps
with st.sidebar:
st.markdown(message)
page = st.selectbox('Select:',moduleNames, format_func=format_func)
# Run the chosen app
modules[moduleNames.index(page)].run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment