Skip to content

Commit

Permalink
MPA v2 tutorial (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dmatthews authored Jun 21, 2024
1 parent 168950f commit e000eca
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import streamlit as st

st.header("Admin 1")
st.write(f"You are logged in as {st.session_state.role}.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import streamlit as st

st.header("Admin 2")
st.write(f"You are logged in as {st.session_state.role}.")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import streamlit as st

st.header("Request 1")
st.write(f"You are logged in as {st.session_state.role}.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import streamlit as st

st.header("Request 2")
st.write(f"You are logged in as {st.session_state.role}.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import streamlit as st

st.header("Respond 1")
st.write(f"You are logged in as {st.session_state.role}.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import streamlit as st

st.header("Respond 2")
st.write(f"You are logged in as {st.session_state.role}.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import streamlit as st

st.header("Settings")
st.write(f"You are logged in as {st.session_state.role}.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import streamlit as st

if "role" not in st.session_state:
st.session_state.role = None

DEFAULT_PAGES = {
None: None,
"Requester": "request/request_1.py",
"Responder": "respond/respond_1.py",
"Admin": "admin/admin_1.py",
}


def login():
roles = DEFAULT_PAGES.keys()

st.header("Log in")
role = st.selectbox("Choose your role", roles)

if st.button("Log in"):
st.session_state.role = role
st.rerun()


def logout():
st.session_state.role = None
st.rerun()


role = st.session_state.role

logout_page = st.Page(logout, title="Log out", icon=":material/logout:")
settings = st.Page("settings.py", title="Settings", icon=":material/settings:")
request_1 = st.Page(
"request/request_1.py",
title="Request 1",
icon=":material/help:",
default=(DEFAULT_PAGES[role] == "request/request_1.py"),
)
request_2 = st.Page(
"request/request_2.py", title="Request 2", icon=":material/bug_report:"
)
respond_1 = st.Page(
"respond/respond_1.py",
title="Respond 1",
icon=":material/healing:",
default=(DEFAULT_PAGES[role] == "respond/respond_1.py"),
)
respond_2 = st.Page(
"respond/respond_2.py", title="Respond 2", icon=":material/handyman:"
)
admin_1 = st.Page(
"admin/admin_1.py",
title="Admin 1",
icon=":material/person_add:",
default=(DEFAULT_PAGES[role] == "admin/admin_1.py"),
)
admin_2 = st.Page("admin/admin_2.py", title="Admin 2", icon=":material/security:")

account_pages = [logout_page, settings]
request_pages = [request_1, request_2]
respond_pages = [respond_1, respond_2]
admin_pages = [admin_1, admin_2]

st.title("Request manager")
st.logo(
"python/api-examples-source/tutorials/dynamic-navigation/images/horizontal_blue.png",
icon_image="python/api-examples-source/tutorials/dynamic-navigation/images/icon_blue.png"
)

page_dict = {}
if st.session_state.role in ["Requester", "Admin"]:
page_dict["Request"] = request_pages
if st.session_state.role in ["Responder", "Admin"]:
page_dict["Respond"] = respond_pages
if st.session_state.role == "Admin":
page_dict["Admin"] = admin_pages

if len(page_dict) > 0:
pg = st.navigation({"Account": account_pages} | page_dict)
else:
pg = st.navigation([st.Page(login)])

pg.run()

0 comments on commit e000eca

Please sign in to comment.