My first page is called recursively

Hi,

I am new to Streamlit and just trying things around, right now, it is multi pages. For some reason, when I add my main page which in this case is app.py to the st.navigation, I get a recursive call on that first page, see sc.

here is my code:

import streamlit as st

home_page = st.Page("app.py", title="Home", icon=":material/home:", default=True)
create_page = st.Page("create.py", title="Create entry", icon=":material/add_circle:")
delete_page = st.Page("delete.py", title="Delete entry", icon=":material/delete:")
compare_page = st.Page(
    "compare.py", title="Compare finance", icon=":material/difference:"
)

pg = st.navigation([home_page, compare_page, create_page, delete_page], position="top")
pg.run()

Also, another question. Is it possible to not have the first page from st.navi selected and loaded? because if I have this

create_page = st.Page("create.py", title="Create entry", icon=":material/add_circle:")
delete_page = st.Page("delete.py", title="Delete entry", icon=":material/delete:")
compare_page = st.Page(
    "compare.py", title="Compare finance", icon=":material/difference:"
)

pg = st.navigation([ compare_page, create_page, delete_page], position="top")
pg.run()

and run streamlit run app.py I will have the page from app.py and compare.py loaded and intertwined .

Thank you in advance for your help!

Hello,
When Streamlit runs app.py, and inside app.py it tells Streamlit to run app.py as a Page, you’re recursively reloading the current file as a subpage, which causes interleaved execution or infinite loops.

You can rename the home page ‘home.py’.

For the second question, I don’t understand what are you trying to achieve. (But perhaps fix the “app.py” will answer it ?)

Just in case it helps to understand:

When you use st.navigation, the file that you streamlit run is not technically a page itself. Instead, think of it like a page router or a picture frame for your pages (of common elements you want to show on all pages, including the navigation widget displayed by st.navigation). As @Faltawer recommends, pull out the parts of app.py you want to display as your “homepage” and move them into another file or function to serve as a distinct page you can include in st.navigation.

1 Like

Thanks for your help. Like you said, using app.py as a router where I just setup the pages and another file with the name home_page.py that has the code for my first page solved both my issues. :face_with_peeking_eye: :grin:
Thanks again :blush: