test_multipage.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import streamlit as st
  2. if "logged_in" not in st.session_state:
  3. st.session_state.logged_in = False
  4. def login():
  5. if st.button("Log in"):
  6. st.session_state.logged_in = True
  7. st.rerun()
  8. def logout():
  9. if st.button("Log out"):
  10. st.session_state.logged_in = False
  11. st.rerun()
  12. login_page = st.Page(login, title="Log in", icon=":material/login:")
  13. logout_page = st.Page(logout, title="Log out", icon=":material/logout:")
  14. dashboard = st.Page(
  15. "reports/dashboard.py", title="Dashboard", icon=":material/dashboard:", default=True
  16. )
  17. bugs = st.Page("reports/data_editor.py", title="Data Editor", icon=":material/edit:")
  18. alerts = st.Page(
  19. "reports/table.py", title="测试表格", icon=":material/notification_important:"
  20. )
  21. search = st.Page("tools/search.py", title="Search", icon=":material/search:")
  22. history = st.Page("tools/history.py", title="History", icon=":material/history:")
  23. if st.session_state.logged_in:
  24. pg = st.navigation(
  25. {
  26. "Account": [logout_page],
  27. "Reports": [dashboard, bugs, alerts],
  28. "Tools": [search, history],
  29. }
  30. )
  31. else:
  32. pg = st.navigation([login_page])
  33. pg.run()