Odd behvaiour with the st.chat_input and the streamlit option menu. The menu option flicks back to the original choice although the page remains changed. See code below to reproduce the result. Any help resolving this would be great. Note that the option menu works fine with st.text_input but when I swap it for st.chat_input the issue arises with the conditional “if” block.
Steps to reproduce
import streamlit as st
from streamlit_option_menu import option_menu
def main():
#st.set_option('deprecation.showPyplotGlobalUse', False)
st.markdown("Welcome")
# menu for document analyzer apps
summary_type = option_menu(
None,
options=["Q&A", "Summarization", "Compare & Contrast", "Output Parsers", "Admin Panel"],
icons=[
"chat-dots-fill",
"file-earmark-text-fill",
"zoom-in",
"table",
"person-fill-lock",
],
menu_icon="cast",
default_index=0,
orientation="horizontal",
key="main_menu"
)
summary_type
if summary_type == "Q&A":
st.markdown("Page 1")
st.chat_input("Enter your message here")
if __name__ == "__main__":
main()
Hi Vicky,
You mean the menu option isn’t flicking back to the original option being selected? I have a video recording of it but I’m not sure how to upload it to streamlit to show…
Yes, while click on the summary button the option flicks and highlighting the Q&A option but showing the summary under the option. You can upload the video on the google drive and share the link here.
I had the same problem, I could not find any solution I finally used st.session to change the default_index value. I’m not sure how good is my method but it worked for my situation
if 'menu_option' not in st.session_state:
st.session_state['menu_option'] =[0,0]
selected_tab= option_menu(
menu_title=None,
options=["1","2"],
orientation="horizontal",
default_index=st.session_state['menu_option'][1] ,
}
)
if selected_tab=="1":
st.session_state['menu_option'][1]=0
if selected_tab=="2":
st.session_state['menu_option'][1]=1
if st.session_state['menu_option'][0] !=st.session_state['menu_option'][1]:
st.session_state['menu_option'][0] =st.session_state['menu_option'][1]
st.rerun()
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.