I'm trying to create a dashboard with a few tabs. The tabs all share common code, and then have specific code to create the tab. I tried using actual tabs, but this runs all the code of all the tabs always. So, for instance, if the user is in tab B, and inputs something, the code will run from the top. It wont run do_commonstuff()
but it will run do_A()
and do_C()
which are independant and dont need to be run again.
I've tried using selectbox instead, but the pages stack up. If I select A, it will print A, then if I select B, it will print B but keep A visible, then if I select A again, it will print it again, and crash because of unique keys.
# User selects which dashboard to view
tab_names = ['A','B','C']
tab = st.selectbox('Select tab', list(tab_names))
# This section I want to run only once
if 'var' not in st.session_state:
st.session_state['var'] = do_commonstuff()
var = st.session_state['var']
# This section I want to run depending on the selection
if tab == 'A': do_A() # this generates a page, including some user inputs
if tab == 'B': do_B() # also
Please help?