St.tabs - How to prevent rerun and jumping back to Tab 1?


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:                                                   
            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))

         with tab2:                                                     
            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)

I hope you can help me.

Thanks in advance!

1 Like

Ok, sorry guys. I guess I missed this entry in the documentation:


All the content of every tab is always sent to and rendered on the frontend. Conditional rendering is currently not supported.

Really, i love Streamlit. But this whole rerun thing is really…

Hope you get rid of this behaviour in the future or make tabs accessable for session states etc. :slight_smile:

Check out the navbar component here

I had the same problem as you, and this solved it for me

1 Like

see the same issue. hope can prevent the tab jump

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’

My tabs don’t jump back to the first tab.

same issue, would be great if tab jump be prevented