Issue with st.tabs

Hi there,

I have a streamlit app that has two tabs on the 2nd and 3rd page. My issue is that the tabs are being duplicated on the frontend even though I have followed the documentation for st.tabs.

Code is as follows:

tab1, tab2 = st.tabs(['Something1', 'Something2'])

with tab1:
    Class DoesOneThing():
         def funtion1:

with tab2:
    Class DoesAnotherThing():
        def anotherFuntion:

The duplicate tabs are directly above the tabs that actaully work when I click them.

Thanks in advance,


I created this version of your code, and it doesn’t show any issues – it is probably related to something happening in one or more of the tabs, but without more detail it’s hard to say what’s happening. Could you give a more complete minimal example that still shows the issue?

import streamlit as st

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

with tab1:

    class DoesOneThing:
        def funtion1():

with tab2:

    class DoesAnotherThing:
        def anotherFuntion():

So I am calling

if __name__ == "__main__":
    class_name= DoesOneThing()

in at the end of the page. I have tried having it nested both in the tab and outside the tab as well.

Hopefully this helps.

I have managed to fix the issue myself, as below

if __name__ == "__main__":
    tab1, tab2 = st.tabs(['Thing1', 'Thing2'])
    with tab1:
        something= classSomething() 

    with tab2:
        something2= classSomething2() 

Glad you got it working!

FWIW, you should get the same behavior if you don’t nest your code in the __name__ == "__main__", and just put it at the bottom of your script.