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

This feels better than changing the working directory at runtime.

2 Likes

Hi
I managed to get it worked.

However, I have another issue. When I use hide_pages, the start of the line of the page is somehow shifted down. Have you seen this before?


1 Like

Is there a way to move the sidebar to the right?
My current code is:

from st_pages import Page, show_pages
show_pages(
    [
        Page("home_view.py", "faz", "🏠"),
        Page("far_view.py", "foo", ":file_folder:"),
        Page("nice_view.py", "bar", ":pencil:"),
        Page("view.py",'sample')
    ]
)

This creates a sidebar to the left, i want the sidebar to the right, how can i achieve this?

1 Like

Hi @Will1, that’s because hide_pages uses css to hide the pages, which involves inserting a small block of html into the page. Unfortunately, I don’t think there’s a way to avoid this, but you could do hide_pages at the end of the app code.

This method doesn’t handle the indentation, but if the main goal is dynamically changing the pages, you could also consider this method New login page navigation example with streamlit 1.31

Hi!

I have a possible lead on the source of the bug that causes the deactivation of customizations on st_pages. Indeed, I am also in a case where it was working very well, and after updating my application with things that are strictly unrelated to page names/icons, etc., st_pages stopped working.

I was using customization in .streamlit/pages.toml, with:

from st_pages import show_pages_from_config
show_pages_from_config(.streamlit/pages.toml)

And it got activated/deactivated without any apparent reason, but still worked locally. However, using:

import os
path_toml = os.path.join(os.getcwd(),".streamlit","pages.toml")
st.write(path_toml)

on my main page, I got two different things :

  • locally :

C:\Users\myname\files\Web app\my_folder\my_repo.streamlit\pages.toml

  • cloud :

/mount/src/my_repo/.streamlit/pages.toml

It worked with:

show_pages_from_config(path_toml)

(and even locally despite the absence of ‘/’ before ‘.streamlit’)

I’m thinking that maybe st_page has trouble managing different paths/Can’t find the toml file?

I should mention that I’m using Windows in France and I have a “packages.txt” file in which I have:

locales
locales-all

With a setting in one of my files:

import locale
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')

I don’t know if this is related, do you have any similarities in your errors?"

What is the error you’re getting?

Also, I assume that this line

show_pages_from_config(.streamlit/pages.toml)

Is actually

show_pages_from_config(".streamlit/pages.toml")

I’m really surprised that os.path.join doesn’t work properly on windows, but you might try this:

from pathlib import Path

raw_path = Path() / ".streamlit" / "pages.toml"

st.write("Path contents", raw_path.read_text())

show_pages_from_config(str(raw_path))

Hi @blackary

I recently stumbled upon the same issue as Debayan.

I have created a streamlit app intented to be used by a lot of people, and I want to control which pages they see in the sidebar on an individual level, of course without updating the view for everybody whenever a user logs on.

Are there any changes that make this possible now?

Yes, you can definitely do that, with a combination of st.experimental_user, and the methods that are now available with 1.31 to dynamically change the sidebar – you can see an example here: New login page navigation example with streamlit 1.31

Perfect! That was exactly the solution we were looking for.

Is there any way to make this menu scrollable like the default navigation menu?

Sure! You can put it in a container with a specific height, and then it will be scrollable