Returning to the right tab after clicking button in 1.24.1


I was previously using version 1.22.0 for deploying my app and the slider button worked fine, in my 2nd tab. Once I deployed it (and since streamlit uses the latest version if not specified), once i used the slider in my 2nd tab, the app reversed back to the 1st tab.

Steps to reproduce

The behavior is quite similar to Returning to the right tab after clicking button
The issue is not there in 1.22.0, but in the latest, it is.

Could this be solved for the latest versions? Thanks!

1 Like

I am currently encountering a similar issue with streamlit version 1.24.0. Wasn’t encountering this issue with versions 1.23.0 or prior.

I have 5 tabs. The tab highlighted in yellow has 5 radio buttons. When I click on the first radio button, the charts relating to that radio button render correctly. When I click on the second radio button, I get redirected to the first tab.

Any help would be appreciated, thank you!

1 Like

The same problem with tabs in version 1.24.0

Same problem here. Was working fine 1.23.1. Updated to 1.24.0 and it’s back to tab 1 every time I activate any input component in another tab.

@tilleul @Akbar_Lutfullah I’m trying to reproduce the issue in 1.24.0 and am using this example code

import streamlit as st

tab1, tab2 = st.tabs(["tab1", "tab2"])

with tab1:
    st.write("This is tab 1")
    st.button("Click me")

with tab2:
    st.write("This is tab 2")
    st.button("Click me, too")"Radio", [1, 2, 3])

But, I am not seeing the issue in 1.24.0. Can you share some code that reproduces the tab switching?

Thanks @blackary, recreated your example code and did not face any issues. Still struggling with my web app though. Attached a gif below add some context. You will note everytime I click on a radio button in the ‘Summary - by site’ tab I get redirected to the ‘Daily Auction Results’ tab. This is odd because as mentioned earlier, up until now I have not experienced this issue with any of the previous Streamlit versions.

The code I am running is very similar to yours i.e. radio buttons within tabs:

st.title("Storage Assets - Commercial")
tab1, tab2, tab3, tab4, tab5 = st.tabs(
    ["Daily Auction Results", "Overview", "Summary - by site", "Summary - all sites", "Portfolio Benchmark"]

with tab1:
    select ='Select a site', options=HEIT_SITES, horizontal=True)
    date = st.date_input("Select a date")
    # code for getting data from external storage, data manipulation and chart creation

with tab3:
    select ='Select a site', options=HEL_SITES, horizontal=True)
    if select == "Contego":
        st.success(f"You selected: {select}")
        slider = st.select_slider(
            "Select a timeframe", options=["Monthly", "Weekly", "Daily"]
    # code for getting data from external storage, data manipulation and chart creation

Just done some further testing. Oddly, no matter which widget I click on (slider, radio button etc.) in any of the tabs, I get redirected to tab 1. Not sure why this is the case. Any help would be appreciated, thank you!

1 Like

Have the same Issues with new version 1.24.1. In my case I used form and submit button inside tabs. Before the version 1.24, it will show some info under the selected tabs, such as ‘Run successfully’. But after updating to 1.24.1, when succeffuly submit forms, it will redirect to the first tab.

I downgrade the version to 1.23 and the problem has gone. Maybe I’ll wait for a newer version to fix this bug.

@blackary I found out that the culprit, in my case, is a st.spinner()

Try this simple code:

import streamlit as st
questions = ["...", "This is option One","This is option Two","This is option Three"]

with st.spinner():
    print ("Do something that is time-consuming ...")

tab1, tab2 = st.tabs(("Open question", "Examples"))

qsel = tab2.selectbox("Select", options=questions)

question = tab1.text_area("Type something")

button = st.button("Submit")

Select tab 2 (“examples”) and select an item in the dropdown list, the page is reloaded and tab1 is displayed … (you may need to do this more than once … for a reason unknown it looks like the behavior is sometimes not triggered …)

Now remove the st.spinner line and the one with print() and the behavior is back to normal.

In v1.23.1 this was working fine with st.spinner …

It looks like there was some change on the st.spinner() widget …

Maybe something in here changed and impacted the behavior of

1 Like

I have locally reverted that change in

changes to

And now it works as before … I don’t know the impact on the other changes made here so I won’t PR … but this is a lead I guess…

It looks like the impact of that change on st.spinner has not been evaluated correctly because in fact, because of that change, EVERY TIME you use a spinner, the whole page is reloaded which is not appealing to the eye (the whole page is rebuild element by element)

Ok it looks like the problem is known and the old behaviour of spinner will be reverted, except when used in chat_message.


Same issues jumpy tabs here. Downgraded to 1.23.0 for now