This is the first time I make a post in a forum so any constructive criticism is accepted, thanks!!
I am running a streamlit app locally, not deployed yet, that uses a Google Auth authentication layer. For now the app on Google Cloud is on trial. I am using streamlit version 1.44.0.
Based on whether the user is logged in or not, I want to show all pages in the ‘pages’ folder or just the log in page. However, after logging in, which works fine, the sidebar shows up but the pages in the ‘pages’ folder do not!
I get an error from streamlit saying it does not find page ‘pages/1_page.py’ and saying that only the page/ subdirectory based on the directory where app.py (the .py file where the log in and log out logic is) is supported.
I clearly am using that subdirectory, so I don’t understand why it won’t show up. In the original version of this streamlit app that does not have an authentication layer, the pages in the pages folder would show up on the sidebar automatically, and here they don’t.
The pages are in maindirectory/pages/ with the format 1_page.py, 2_page.py, etc.
The error code is:
streamlit.errors.StreamlitPageNotFoundError: Could not find page: pages\0_Bienvenida.py
. You must provide a file path relative to the entrypoint file (from the directory StreamlitLogin-Prueba
). Only the entrypoint file and files in the pages/
directory are supported.
Traceback:
File "C:\Users\pablo.sierra\Documents\GitHub\StreamlitLogin-Prueba\app.py", line 40, in <module>
st.sidebar.page_link(page_path, label=page_name)File "C:\Users\pablo.sierra\AppData\Local\anaconda3\envs\loginstreamlit\Lib\site-packages\streamlit\runtime\metrics_util.py", line 410, in wrapped_func
result = non_optional_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\pablo.sierra\AppData\Local\anaconda3\envs\loginstreamlit\Lib\site-packages\streamlit\elements\widgets\button.py", line 698, in page_link
return self._page_link(
^^^^^^^^^^^^^^^^File "C:\Users\pablo.sierra\AppData\Local\anaconda3\envs\loginstreamlit\Lib\site-packages\streamlit\elements\widgets\button.py", line 888, in _page_link
raise StreamlitPageNotFoundError(
My app.py code is:
import streamlit as st
import os
def login_screen():
st.header(“This app is private.”)
st.subheader(“Please log in.”)
if st.button(“Log in with Google”):
st.login()
if not st.experimental_user.is_logged_in:
login_screen()
# Hide sidebar until user logs in
st.markdown(
"""
<style>
[data-testid="stSidebar"] {display: none;}
</style>
""",
unsafe_allow_html=True,
)
else:
st.title(“Welcome!”)
st.write(f"Hello, {st.experimental_user.email}!")
st.sidebar.title("Navigation")
pages_dir = "pages"
if os.path.exists(pages_dir):
pages = sorted([f for f in os.listdir(pages_dir) if f.endswith(".py")])
for page in pages:
page_path = os.path.join(pages_dir, page)
page_name = page.replace("_", " ").replace(".py", "").title()
st.sidebar.page_link(page_path, label=page_name)
if st.button("Log out"):
st.logout()