streamlit-navigation-bar
streamlit-navigation-bar copied to clipboard
Extra Rerun on page switch
Checklist
- [X] I have searched the existing issues for similar issues.
- [X] I added a very descriptive title to this issue.
- [X] I have provided sufficient information below to help reproduce this issue.
Summary
It appears that when using the navigation bar, there is an extra re-run that is triggered when rendering for the first time. For example - if I am on page 'home' and navigate to 'page 1' - in my terminal i notice that if I am printing anything it prints twice.
Reproducible code example
###home.py
import streamlit as st
from streamlit_navigation_bar import st_navbar
st.set_page_config(initial_sidebar_state="collapsed")
styles = {"div": {"max-width": "350px"}} # Reduce the page names spacing.
page = st_navbar(["Home", "Page 1", "Page 2"], styles=styles)
if page == "Page 1":
st.switch_page("pages/page_1.py")
if page == "Page 2":
st.switch_page("pages/page_2.py")
print('last')
# Home content goes here, for example:
st.write("Foo")
### page 1
import streamlit as st
from streamlit_navigation_bar import st_navbar
st.set_page_config(initial_sidebar_state="collapsed")
styles = {"div": {"max-width": "350px"}} # Reduce the page names spacing.
page = st_navbar(["Home", "Page 1", "Page 2"], selected="Page 1", styles=styles)
if page == "Home":
st.switch_page("home.py")
if page == "Page 2":
st.switch_page("pages/page_2.py")
print('check')
# Page 1 content goes here, for example:
st.write("Bar")
Steps to reproduce
Run the above code and watch your terminal as you switch pages
Expected behavior
My understanding is there would just be a single run on initiation.
Current behavior
No response
Is this a regression?
- [ ] Yes, this used to work in a previous version.
Debug info
- Streamlit version:
- Streamlit Navigation Bar version:
- Python version:
- Operating System:
- Browser:
Additional information
No response