admin管理员组文章数量:1026397
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?
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?
本文标签: pythonHow to create a streamlit dashboard that runs only the selected tabStack Overflow
版权声明:本文标题:python - How to create a streamlit dashboard that runs only the selected tab - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745649953a2161257.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论