-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
168950f
commit e000eca
Showing
10 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
python/api-examples-source/tutorials/dynamic-navigation/admin/admin_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") |
4 changes: 4 additions & 0 deletions
4
python/api-examples-source/tutorials/dynamic-navigation/admin/admin_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") |
Binary file added
BIN
+38.5 KB
python/api-examples-source/tutorials/dynamic-navigation/images/horizontal_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.14 KB
python/api-examples-source/tutorials/dynamic-navigation/images/icon_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
python/api-examples-source/tutorials/dynamic-navigation/request/request_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") |
4 changes: 4 additions & 0 deletions
4
python/api-examples-source/tutorials/dynamic-navigation/request/request_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") |
4 changes: 4 additions & 0 deletions
4
python/api-examples-source/tutorials/dynamic-navigation/respond/respond_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") |
4 changes: 4 additions & 0 deletions
4
python/api-examples-source/tutorials/dynamic-navigation/respond/respond_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") |
4 changes: 4 additions & 0 deletions
4
python/api-examples-source/tutorials/dynamic-navigation/settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") |
84 changes: 84 additions & 0 deletions
84
python/api-examples-source/tutorials/dynamic-navigation/streamlit_app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |