I currently have the following problem with the tabs. I added two tabs on my page and in both select boxes as an example. If I change the select box in Tab 2, the program jumps back to Tab 1.
I know I can use a form with a button. However, as soon as the button is pressed and a function is executed in the background, the program also jumps back to Tab 1.
I don’t think this can be intentional. How can I stop this behavior? Is there a way to read and cache the index of the tabs?
Here is some example code:
tab1, tab2 = st.tabs(option_menu_database)
with tab1:
st.header("View")
with st.form("database_view"):
db_tables = pd.DataFrame(database_tables())
selected_table = st.selectbox("Tables",db_tables)
if st.form_submit_button("Load tables"):
db_table = pd.DataFrame(database_get_table(selected_table))
st.write(db_table)
with tab2:
st.subheader("Edit")
with st.form("database_edit"):
select_choice = st.selectbox("What do you want to edit?",("Database","Table"))
if st.form_submit_button("Load"):
db_tables = pd.DataFrame(database_get_table(select_choice))
selected_table = st.selectbox("Tables",db_tables)
st.markdown("---")
I have the same issue, I tried the hydralit_components, I found it re-runs when switch tabs, but streamlit tab doesn’t rerun. Not sure which one I prefer since I like ‘switch tab and no rerun’ + ‘tabs don’t jump back to tab1’
Is there any plan to support fixes for this? Currently seeking to use tabs in Streamlit apps hosted in Snowpark, and it appears to follow little rhyme/reason about re-rendering and jumping back to the first tab.
One might think this is due to session_state data being modified across tabs, but alas, no - completely decoupled session_state variables for tab3, compared to tab1 and tab2 (who share some session state). Absolutely no jumping back from tab2 to tab1, when UI elements are interacted with. But anything that causes a cleaning of UI widgets in tab3 forces tab1 to regain focus.
It would be helpful to know if elegant tab behavior will be supported without use of custom components (note the Streamlit-in-Snowpark reference), or if we should seek alternative UI/UX options.
+1 here. I saw another issue which advised declaring the tabs as the first streamlit call to work around this but (a) we want our tab bar below our dashboard title and (b) I believe the fact we are importing functions which run st commands is interfering too.
Is there an issue in github for this problem given how many times it has come up in discussions here?
For now, I used st.radio with some CSS hack to make it look like a tab. My use case was slightly different; I want to only render content of tabs that is selected.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.