Can you check to see if you have the latest version of st_pages installed? You can see that code working fine here https://st-pages-sections.streamlit.app/
Very cool!!!
Hey @blackary, I have built a streamlit app (in version 1.11.1) where all pages are defined in the pages folder in a particular order. I wish to hide all pages before user logs into the app and was tryingt he follow the approach you’ve mentioned above.
I’m tried to import different modules from st_pages as suggested above, but I’m getting an error that says: cannot import name ‘runtime’ from ‘streamlit’. What shall I try next?
The best solution will probably be to upgrade to a more recent version of streamlit
Yeah it works after upgrading the library, thanks!
i managed to get it working finally! i decided to use the pages.toml file.
a few remarks though:
- You cant leave the icon field behind, if you dont want to use it, you have to specify that its empty:
wrong:
[[pages]]
path = “script.py”
name = “Page Name”
correct:
[[pages]]
path = “script.py”
name = “Page Name”
icon = “”
- Some of the emojis inside the icon string wont be recognized and giving an error, i decided to place all emojis and icos inside the page name.
correct:
[[pages]]
path = “script.py”
name = “ Page Name”
icon = “”
Hi @Christian, thanks for the feedback.
You shouldn’t need to add an empty icon – you can see an example here that doesn’t specify an icon, and it works fine https://github.com/blackary/st_pages/blob/main/example_app/.streamlit/pages.toml#L21
What do you mean by icons “won’t be recognized”? Can you give an example of one that isn’t recognized?
Hi! Could you please help to solve an issue? I’ve got st_pages working fine at my localhost, but when deployed at Streamlit Cloud the app just shows a default sidebar.
I’m using show_pages, not a .toml file as I map my pages names to a dictionary to switch languages. Like this:
show_pages(
[
Page(“Home.py”, text[‘menu_home’][st.session_state[‘language’]], “”),
Page(“pages/1_Forecast.py”, text[‘menu_forecast’][st.session_state[‘language’]], “”),
Page(“pages/2_Archive.py”, text[‘menu_archive’][st.session_state[‘language’]], “”)
]
)
Actually the language switch is why making pages display properly means so much to me. Could you please advise?
UPD: i tried to use .toml file instead at Home page and this way it works both locally and online. Interestingly sidebars at other pages are also displayed correctly, though they remain in show_pages notation. Unfortunately they don’t change when the language is switched (locally they do)
Then i thought i could create two versions of a page inside my pages.toml for the two languages and use hide_pages for those in inactive language. But it appeared you can’t map a single file to two pages instances, it sees just the last one. So i had to duplicate all my pages. When a page is being loaded for a couple of seconds i can see all of them, in both languages, then the inactive one disappear. This solution seems an ugly crutch, so i still hope anybody hepls me to get this work properly. Thanks
Hi again @blackary! There is another issue that I’m facing with session_state. I have used pandarallel library to parallelize my code across cores but it requires variables and libraries to be explicitly defined and imported for the function being parallelized.
Now, I’m saving a username for the user on the Home page and wish to persist it across all pages, but calling it with st.session_state[‘session_username’] on a new page is not working with pandarallel. Is there another way to persist it without using session state?
Hi @Radhika_Sachdev this sounds unrelated to st_pages, could you please create a new post and include in there code that demonstrates the issue?
Hey all,
I’m having an issue with st_pages.
When running locally in PyCharm everything is good with the show_pages() command. But inside a docker container it does not give any error but the names are not changed and take the name of the files.
I’m trying to set the pages.toml but I can’t seam to figure how to make it work even locally:
I have a folder called webapp where I have the root home.py where the streamlit app starts and a folder .streamlit/pages.toml in the same level as home.py but I always get the error Could not find a valid .streamlit/pages.toml file.
Edit: nvm fixed it. had the root of working project changed to the same level as home.py and now it works.
I’m having the same experience. There is no pattern. Sometimes work, sometimes not work
Same issue here where st-pages is working fine locally, but is not working on the cloud: https://stock-tracker-magic-formula.streamlit.app/. I am using the toml method.
@Yohanes_Partogi Yes, you can do add_page_title(layout="wide")
like this st_pages/example_app/example_one.py at main · blackary/st_pages · GitHub
If you’re not using add_page_title
in your app, just do st.set_page_config(layout='wide')
Not working on Streamlit cloud app. worked only for local.
I also have the same issue that it doesn’t work on streamlit cloud although it works fine locally.
The demos of @blackary still work however, so we must be doing something wrong but I can’t figure out what.
The error message I get on streamlit cloud is a file not found error for example:
FileNotFoundError: [Errno 2] No such file or directory: '/mount/src/structize/pages/create.py'
Could somebody help me out and explain how to fix this?
Hello,
I’ve encountered similar issues when trying to set up a proper working directory locally or on the cloud using:
os.chdir(os.path.dirname(os.path.realpath(__file__)))
When I started working with st_pages
, for some unknown reason, this line of code would throw an error saying “File not found…”. I managed to resolve this issue by modifying the code as follows:
new_dir = os.path.dirname(os.path.realpath(__file__))
if os.path.exists(new_dir):
os.chdir(new_dir)
his approach first checks for the directory’s existence before attempting to change the working directory, which avoids the mentioned error.
I hope this can help others facing the same issue.
Thanks for the tip!
I found the issue. It seems to occur when your streamlit is in a subfolder. So I just looked for the parent_directory
and changed my code to this when adding the pages and that fixed it:
Page(os.path.join(parent_directory, "streamlit_home.py"), "Home")