New package st-pages: change page names and icons in sidebar without changing filenames

You were right! It’s started showing up since yesterday. It’s been two weeks since I first launched it, but only two days since I shared it with public on the forum and my LinkedIn.

1 Like

Hi everyone,

It’s me again. I noticed that once in a while, the st_pages “stop working” on my deployed public app, even though it always works on my localhost. I’ve been trying to identify what pattern could cause that for the past couple of weeks (e.g., sometimes it seemed to happen when I updated the requirements.txt file, sometimes when I added a new page). However, I couldn’t spot a consistent pattern. For example today, it seems to be not working again, even though it did work last night after my most recent update on GitHub. I did not change anything on the app since last night.

It usually gets fixed after I reboot the app, but not always. I also want to avoid rebooting the app to avoid interuptions in the usage.

Has anyone else experienced anything along those lines? I wonder if there’s something wrong with the way my app folder or code is structured - would appreciate any help on that.

See photo attached below - these page names correspond to the file names but not to those specified in “pages.toml”.

Thank you for your feedback!

2 Likes

Huh, that’s odd :confused:

Could you try something odd – could you move the show_pages_from_config to the end of your intro.py script? I’ve had cases in internal apps where that was necessary and I haven’t yet figured out why.

I tried a few things but nothing seemed to help so far. :face_with_diagonal_mouth:

Rebooting after each step:
1. Adding show_pages_from_config() to the bottom of intro.py – didn’t work
2. Adding show_pages_from_config() to each page
3. Adding show_pages_from_config() to the bottom of each page
4. Removing show_pages_from_config() from all pages except intro.py

Could the pip upgrade warning cause any issues? It’s been there ever since and I read it shouldn’t be a problem, so I assume not, but maybe you have other thoughts?

WARNING: You are using pip version 22.0.3; however, version 23.3 is available.
You should consider upgrading via the '/home/adminuser/venv/bin/python -m pip install --upgrade pip' command.

Ok the strangest thing happened - I used the hyperlink which led to the URL of one of the pages with show_pages format (https://phd-econometrics.streamlit.app/OLS%20in%203D) and now it started showing up properly again. I assumed it would have given a “page not found” error and yet it solved the problem.

Still no clue how or why, but I’ll do that if it happens again to confirm.

1 Like

Hello, i found problems when i first run my app, the indentation on my Sections and pages does not appear until I first rerun the app, or i make any interaction with the app(swittch pages…)

    def pages(self):
        add_indentation()
        show_pages(pages=
       [
         Page("landing.py", "Home"),
         Section(name= "Iberdrola"),
         Page("otherPages/edicionDatos.py", " - Consulta de datos"),
         Page("otherPages/insercionDatos.py", " - Inserción de datos" ),
         Section(name= "Endesa"),
         Page("otherpages/edicionDatosEnd.py", " - Consulta de datos"),
         Page("otherpages/insercionDatosEnd.py", " - Inserción de datos"),
         Page("otherPages/usersManagement.py","Permisos", in_section = False)
       ]
       #hide_pages()
     )

I have my configuration of pagination inside a class and call it at every page pnñy if users have logged in, could anyone please tell me what happened?

Do add_indentation after you do show_pages and that should fix it.

1 Like

Thank you!

2 Likes

Hi again, i was wondering if it is possible to add some customization to the sidebar without overlapping the pages index with the ilustrative content i want to add to the sidebar?

i want to add and image and title like this:


    def add_logo(self, logo):
        
        f = open(logo, "rb")
        imgCode = f.read()
        backGround = base64.b64encode(imgCode).decode()

        logo = f"""
            <style>
                [data-testid="stSidebarNav"] {{
                    background-image: url("data:image/png;base64,{backGround}");
                    background-repeat: no-repeat;
                    padding-top: 120px;
                    background-position: 20px 20px;
            }}
            [data-testid="stSidebarNav"]::before {{
                content: "Redes IDEA";
                margin-left: 20px;
                margin-top: 20px;
                font-size: 30px;
                position: relative;
                top: 100px;
            }}
            </style>
            """
        return st.markdown(logo, unsafe_allow_html=True)

and this happens:

or is it possible keep expanded the page index of my app as an alternative???

just like that

thanks in advance for answering

1 Like

You can look at the source code of 🐱 App logo - streamlit-extras to see the css that I use there to move the normal menu down to insert a logo.

1 Like

Has anyone been using this with st-paywall?
I getting some bugs, after a user login I need to press R to reload, and then be able to update the pages allowed for that user.
Any other example of using this with login control is welcome!
Best.

Hi everyone, i´m findig some problems regarding the st-pages app.

When i first run my app, on the home page (landing.py), the app crashes on the first click inside this home page. With the warning of page not found, the app reruns automatically and then all the content is displayed properly and no problems are found.

I use streamlit oauth to log in and no content is displayed until the user logs in.

the code is the following:

with st.sidebar:
    # Inicio sesion en Azure: 
    status = fun.azureLogin()
    
if status == 200:
    fun.pages()
#[...] Here some code regarding session state config and css custom styles
with col1:
    if status == 200:

        # Crear las pestañas
        tab = st.radio('Selecciona un tablón de anuncios', ['Expedientes sin gestionar', 'Alertas de usuario', 'Expedientes Asignados'], horizontal= True)
#[...] rest of the code within each tab

and te pages is here:

    def pages(self):
        
        show_pages(pages=
       [
         Page("landing.py", "Home"),
         Section(name= "Iberdrola"),
         Page("otherPages/edicionDatos.py", " - Consulta de datos"),
         Page("otherPages/insercionDatos.py", " - Inserción de datos" ),
         Section(name= "Endesa"),
         Page("otherpages/edicionDatosEnd.py", " - Consulta de datos"),
         Page("otherpages/insercionDatosEnd.py", " - Inserción de datos"),
         Section(name= "Gestión"),
         Page("otherPages/usersManagement.py"," - Permisos")
       ]
     )
        add_indentation()

dont´know if you need the full code, in this case reply and ask me, the screenshot is like that:


this image is before logging in

this is before doing any interaction on this page

after the first click on any widget of the page

colud please someone tell me what is the problem? Thanks in advance

1 Like

I would recommend doing this slightly differently:

  1. Always add all pages (i.e… always run the pages() function, no matter what)
  2. Hide the pages using the hide_pages() method

I suspect this will solve the issue – if that still doesn’t work, could you share a link to your repo?

1 Like

Hi again, and thanks for answering, im not sure if im implementing the st-pages component properly, do i have to add the show pages in all of the pages of the app, or only on the main page (my landing).

I use the hide pages clause on my script after specifying the show pages but it does not apply to the app.

1 Like

I have tried to run my app without using the contidion of showing all the pages only when loggin in, just show them by default, and the same warning appears, the page not found, i don´t know if is not neccesary to add the landing page on the show pages_() function.

Here’s a super simple example

import streamlit as st
from st_pages import Page, hide_pages, show_pages

show_pages(
    [
        Page("home.py", "Home", "🛖"),
        Page("pages/page1.py", "Page 1", "🦖"),
        Page("pages/page2.py", "Page 2", "🦜"),
    ]
)

username = st.text_input("Username")

if not username:
    hide_pages(["Page 1", "Page 2"])

This only shows the home page unless you type in a username, and then it shows the other two pages.

It is necessary to add the landing page to the list of pages.

1 Like

I got it but the problem of the page not found still appearing, i have tried all your recommendations but im not able to find the solution for this problem.

Other important thing to take into account, is that if a try to debug the source code of the app step by step, the problem of page not found disappears on the exact same actions in the app.

I have the same issue
image
image

do you have any workaround?

This is the second time posting on this thread but under my work account, i still wanted to give it a second go, but it get the following error:

UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x90 in position 122: character maps to

1 Like