diff --git a/python/api-examples-source/tutorials/dynamic-navigation/admin/admin_1.py b/python/api-examples-source/tutorials/dynamic-navigation/admin/admin_1.py new file mode 100644 index 000000000..9ea5c67c1 --- /dev/null +++ b/python/api-examples-source/tutorials/dynamic-navigation/admin/admin_1.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Admin 1") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/python/api-examples-source/tutorials/dynamic-navigation/admin/admin_2.py b/python/api-examples-source/tutorials/dynamic-navigation/admin/admin_2.py new file mode 100644 index 000000000..cdac57a88 --- /dev/null +++ b/python/api-examples-source/tutorials/dynamic-navigation/admin/admin_2.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Admin 2") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/python/api-examples-source/tutorials/dynamic-navigation/images/horizontal_blue.png b/python/api-examples-source/tutorials/dynamic-navigation/images/horizontal_blue.png new file mode 100644 index 000000000..05a00969d Binary files /dev/null and b/python/api-examples-source/tutorials/dynamic-navigation/images/horizontal_blue.png differ diff --git a/python/api-examples-source/tutorials/dynamic-navigation/images/icon_blue.png b/python/api-examples-source/tutorials/dynamic-navigation/images/icon_blue.png new file mode 100644 index 000000000..96bce1171 Binary files /dev/null and b/python/api-examples-source/tutorials/dynamic-navigation/images/icon_blue.png differ diff --git a/python/api-examples-source/tutorials/dynamic-navigation/request/request_1.py b/python/api-examples-source/tutorials/dynamic-navigation/request/request_1.py new file mode 100644 index 000000000..0b177a60e --- /dev/null +++ b/python/api-examples-source/tutorials/dynamic-navigation/request/request_1.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Request 1") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/python/api-examples-source/tutorials/dynamic-navigation/request/request_2.py b/python/api-examples-source/tutorials/dynamic-navigation/request/request_2.py new file mode 100644 index 000000000..659efb5ff --- /dev/null +++ b/python/api-examples-source/tutorials/dynamic-navigation/request/request_2.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Request 2") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/python/api-examples-source/tutorials/dynamic-navigation/respond/respond_1.py b/python/api-examples-source/tutorials/dynamic-navigation/respond/respond_1.py new file mode 100644 index 000000000..652a106ea --- /dev/null +++ b/python/api-examples-source/tutorials/dynamic-navigation/respond/respond_1.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Respond 1") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/python/api-examples-source/tutorials/dynamic-navigation/respond/respond_2.py b/python/api-examples-source/tutorials/dynamic-navigation/respond/respond_2.py new file mode 100644 index 000000000..fc987ca3b --- /dev/null +++ b/python/api-examples-source/tutorials/dynamic-navigation/respond/respond_2.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Respond 2") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/python/api-examples-source/tutorials/dynamic-navigation/settings.py b/python/api-examples-source/tutorials/dynamic-navigation/settings.py new file mode 100644 index 000000000..bd2cbbef4 --- /dev/null +++ b/python/api-examples-source/tutorials/dynamic-navigation/settings.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Settings") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/python/api-examples-source/tutorials/dynamic-navigation/streamlit_app.py b/python/api-examples-source/tutorials/dynamic-navigation/streamlit_app.py new file mode 100644 index 000000000..f0bcc0c31 --- /dev/null +++ b/python/api-examples-source/tutorials/dynamic-navigation/streamlit_app.py @@ -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() \ No newline at end of file