I am using the chat_input and chat_message functionality to create a chatbot. I have some suggestions in the sidebar as markdown. I was wondering, how I could make the suggestions clickable, so that they would populate the chat_input on click, and it wouldn’t look weird having each text wrapped as a button or something.
For each of the suggestion, you may assign it to the st.radio widget if you want only 1 to be selected or to st.checkbox in order to allow multiple selections. You could also look into using the component streamlit-pills as well.
Thanks for the suggestions. I’m now using streamlit-pills to give suggestions for the chatbot but I have an issue, once you click on a suggestion it remains selected in the next chat loop and then the chatbot keeps responding the same question. I would need to reset the pills widget then. I usually can do this with other widgets by defining an empty container like
empty_container = st.empty()
empty_container.selectbox()
... do stuff
#Reset selectbox
empty_container.selectbox()
How could I do this with pills or another way to deselect the clicked pill?
st.empty() would allow to reset the output display as for the value of variable using streamlit-pill we may have to try another way. Could you try assigning the values from streamlit-pill widget to a session state variable and use a callback function that resets the variable using the streamlit-pill widget to its default state once it is selected.
I tried something similar with setting the index on a session variable to None but it didn’t work. So I tried setting the list of query options in a session variable and each time the user chooses one option it is eliminated from the list and the pills widget is recreated. That’s the only way I could make it work.
# Get rid of the suggestion now that it was chosen
if predefined_prompt_selected:
index_to_eliminate = st.session_state.suggestions_list.index(predefined_prompt_selected)
st.session_state.suggestions_list.pop(index_to_eliminate)
st.session_state.suggestions_icons.pop(index_to_eliminate)
@Odrec@dataprofessor
I got the overall idea but how can I pass the selected predefined_prompt_selected to st.chat_input() as there is no value parameter to it? Please help me with this as soon as possible.
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.