blackary / st_pages

An experimental version of Streamlit Multi-Page Apps
MIT License
467 stars 77 forks source link

St-pages doesn't work properly on Streamlit Cloud environment #85

Closed patrykpalej closed 3 months ago

patrykpalej commented 11 months ago

I have an app with a very simple structure. I use st-pages there and everything works fine on my server. However when I send it to the Streamlit cloud, the pages names aren't rendered properly.

I know it may be related to environment, because the app works on my server, however maybe something can be changed to support Streamlit cloud as well?

Here is my code and deployed app:

https://github.com/patrykpalej/Real-Estate-Market-Analysis-dashboard/

https://real-estate-market-pl.streamlit.app/

Btw. I tried to setup my app with multiple combination in terms of setting PYTHONPATH, append sys.path etc. It looks like the behaviour was indeterministic, because sometimes it works, sometimes it doesn't and I cannot tell what's wrong and why.

blackary commented 10 months ago

I'm not really sure why this is happening, but I think it has something to do with the fact that importing this file actually runs some code, because if I move the connection_string code inside of the fetch_and_preprocess it works for me. I would recommend doing that in general -- don't make importing a module actually run code.

I would also highly recommend you look into st.secrets for your credentials, rather than using os.environment https://docs.streamlit.io/streamlit-community-cloud/deploy-your-app/secrets-management, but that's probably unrelated.

patrykpalej commented 10 months ago

You mean such a change? -> https://github.com/patrykpalej/Real-Estate-Market-Analysis-dashboard/blob/master/functions/data_loading.py

I rebooted the app in the cloud after push but pages names still aren't visible. Did you mean that it works for you locally or in the cloud? In my local environment it works as well. The only problem is in the streamlit cloud.

I will try st.secrets, havn't heard about it before.

blackary commented 10 months ago

Sorry, I'm really not sure what's going wrong here -- I made a super simplified repo with two files and it works fine

import streamlit as st
from st_pages import Page, show_pages

st.set_page_config(layout="wide", page_title="Real Estate Market Analysis")

show_pages(
    [
        Page("streamlit_app.py", "Project description", "💻"),
        Page("pages/test.py", "Houses", "🏡"),
    ]
)

https://pages-test-avvfxcd95pfsnn9rwueqxg.streamlit.app/

I'm really not sure what's going wrong with your app :/

The good news is that you can use streamlit's native multipage app features as an alternative, you just have to add emojis to the filenames to add them to the sidebar https://docs.streamlit.io/library/get-started/multipage-apps/create-a-multipage-app

patrykpalej commented 10 months ago

Yeah, I'll stick with traditional approach for handling pages. Maybe in future releases this issue will be overcome. Thank you for the feedback.

What's most interesting is that during the development process sometimes the pages were handled correctly, but then after new changes it corrupted again.

Yelinz commented 10 months ago

Heyo I have the same problem. It seems to apply the layout wide but nothing else.

https://github.com/Yelinz/commute-city-triangulation/blob/777ea3f66416d21277b48713788cde1f8391bf75/main.py#L19 https://commute-triangulation.streamlit.app/

danilo-css commented 9 months ago

@blackary I had the same problem and solved it adding "is_section=true" at the last page of my page list.

Seems that for it to work on Streamlit Cloud now at least 1 page has to have "is_section=true". If none have it doesn't work.

patrykpalej commented 9 months ago

@blackary I had the same problem and solved it adding "is_section=true" at the last page of my page list.

Seems that for it to work on Streamlit Cloud now at least 1 page has to have "is_section=true". If none have it doesn't work.

I checked and it seems to work. Thank you!

blackary commented 3 months ago

This is very likely resolved in the latest release of st-pages