Multi-page app (ver. 1.36)

I redesigned my app to be multi-page. Pages navigation and other features work fine, but when the user is not on the main page and presses the refresh or F5 button, the page freezes and doesn’t display any content.

Hi @Vyacheslav!

Could you share a link to your repo, or a minimal reproducible script that shows how you are setting up the main page, and the setting page?

Are you using the setup with a pages/ folder, or using the new st.navigation?

Actually, it looks like this is a known issue that will be fixed in the next release Page not reloading when using st.navigation() · Issue #8986 · streamlit/streamlit · GitHub

Can you try installing streamlit-nightly and see if that fixes the issue for you?

2 Likes

I use st.navigation

import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader

st.set_page_config(page_title="dashboard", layout="wide", page_icon=":bar_chart:")  

if "role" not in st.session_state:
    st.session_state.role = None

my_kpi_page = st.Page("userpages/0_kpi.py", title="My KPI", icon= "📶")
settings_page = st.Page("adminpages/settings.py", title="Settings", icon="🔑")
# 
empty_page = st.Page("userpages/logout_page.py", title=None, icon=None,default=True)

def get_page_by_role(role_user):

    pages = None
    if (role_user == "admin"):
        pages = {
             "Main" : [my_kpi_page],
             "Settings": [settings_page]
        }  
    else:
        pages = [empty_page]
        return pages
    
    return pages


def main():

    with open('./config.yaml') as file:
        config_ath = yaml.load(file, Loader=SafeLoader)
        cred_dict = config_ath['credentials']
        cookie = config_ath['cookie']

    authenticator = stauth.Authenticate(cred_dict,
                                        cookie["name"],
                                        cookie["key"],
                                        cookie_expiry_days = cookie["expiry_days"]
                                        )
    
    name, authenticator_status, username = authenticator.login()

    if authenticator_status == False:
            st.error("Username/password is incorrect")
            st.session_state.role = None
            st.stop()

    if authenticator_status == None:
        st.warning("Please enter username and password")
        pages_user = get_page_by_role(None)
        pg = st.navigation(pages_user)
        pg.run()
        st.session_state.role = None
        st.stop()

    if authenticator_status:
        
        group_user = (cred_dict['usernames'][st.session_state["username"]]["group"])      

        st.session_state.role = group_user
        
        #--SIDEBAR----
        st.sidebar.write(f"Login: {username}")
        st.sidebar.caption(group_user)
        authenticator.logout("Logout", "sidebar")
        

        pages_user = get_page_by_role(st.session_state.role)
        pg = st.navigation(pages = pages_user , position="sidebar")
        #RUN NAVIGATION
        pg.run()


if __name__ == '__main__':
    hide_st_style = """
                <style>
                #MainMenu {visibility: hidden;}
                footer {visibility: hidden;}
                </style>
                """
    st.markdown(hide_st_style, unsafe_allow_html=True)
    
    main()

Thanks :smiley:

This is also broken in the pages subfolder mechanism. Hope it is also fixed in the upcoming release. Thanks.

I have the same issue

So I decide to downgrade to ver. 1.35, I had the same issue.

1.37 has now been released, so this should be fixed if you upgrade