python - How to create a streamlit dashboard that runs only the selected tab - Stack Overflow

I'm trying to create a dashboard with a few tabs. The tabs all share common code, and then have sp

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745649955a4638203.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信