How to hide pages of multiweb page app using st-pages?

To display pages in the main .py file, I use show_pages as follows:

from st_pages import hide_pages, show_pages, Page

show_pages(
    [
        Page("app.py"),
        Page("pages/1_A.py"),
        Page("pages/2_B.py"),
    ]
)

But what if I want to hide a page using hide_pages ?
If I add to the code above:

hide_pages(
    [
        Page("pages/test.py"),
     ]
)

And then I want to open a test page using the url http://localhost:8501/test,
it prints:

Page not found

You have requested page /test, but no corresponding file was found in the app’s pages/ directory. Running the app’s main page.

Doesn’t the call to hide_pages actually hide the pages?

According to the documentation, these pages should only be hidden via CSS and can still be visited using the URL.

 These pages are only hidden via CSS, and can still be visited by the URL.

That is right.

And if i try to open the hidden page using URL it says:

Page not found

You have requested page /test, but no corresponding file was found in the app’s pages/ directory. Running the app’s main page.

To better clarify the issue: Page not found: no corresponding file was found · Issue #80 · blackary/st_pages (github.com)

@blackary Would you be able to help? Thank you in advance :pray:

the following code should work:

from st_pages import show_pages, hide_pages, Page


show_pages(
    [
        Page("home.py"),
        Page("pages/test.py"),
        Page("pages/example.py"),
    ]
)

hide_pages(
    [
        "Example",#correct use name
    ]
)

ImportError: cannot import name ‘show_pages’ from ‘st_pages’
How to solve this?
Also I found hide_pages is overwritten if we have Python scripts inside the pages folder
How to overcome this?

I was not able to get this hide_pages, and show_pages functionality to work. However the purpose I tried to get this to work was because of the sidebar.
This streamlit discussion
Go inspect the source code and was able to disable the sidebar/navbar completely.
For me the data-testid is “stSidebar”

st.markdown(
    """
<style>
    [data-testid="stSidebar"] {
        display: none
    }

</style>
""",
    unsafe_allow_html=True,
)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.