thanks for reply …please correct my code.
st.write(“after click”) not processing in the below code. (checked is not TRUE)…may be this code is inside with statement ?
for button_info in button_info_list:
button_title = button_info.get("title", "")
payload = button_info.get("payload", "").lstrip("/")
checked = st.checkbox(label=button_title, key=payload)
if checked:
st.write("after click")
thank you. please check now…when i click any of the button…nothing happens…kindly advice how to change code.
import streamlit
import streamlit as st
from streamlit_chat import message
import streamlit as st
if user_input := st.chat_input("You:"):
with st.chat_message("user"):
st.markdown(user_input)
bot_reply = st.write(user_input)
assistant_responses = ""
if bot_reply:
assistant_responses = 'test'
button_info_list = ""
else:
assistant_responses = "I'm sorry, but I don't understand that input. Please provide a valid request.."
with st.chat_message("assistant"):
button_info_list = [{"title": "Title", "payload": "Foo"}, {"title": "Another title", "payload": "Payload"}]
for button_info in button_info_list:
button_title = button_info.get("title", "")
payload = button_info.get("payload", "").lstrip("/")
checked = st.checkbox(label=button_title, key=payload)
if checked:
st.write("after click")
@B_Ismail Any widget interaction causes the app to be rerun from top to bottom, so clicking the button will rerun the app from the top, and see that (since you already sent the chat message), user_input is empty, so nothing else will appear. If you store the sent messages in st.session_state, you can see the messages and the buttons persist and continue to work.
import streamlit as st
if "messages" not in st.session_state:
st.session_state["messages"] = []
if user_input := st.chat_input("You:"):
st.session_state["messages"].append(user_input)
for idx, message in enumerate(st.session_state["messages"]):
st.write(f"User: {message}")
bot_reply = "Test bot reply"
st.write(f"Bot: {bot_reply}")
button_info_list = [
{"title": "Title", "payload": "Foo"},
{"title": "Another title", "payload": "Payload"},
]
for button_info in button_info_list:
button_title = button_info.get("title", "")
payload = button_info.get("payload", "").lstrip("/")
if st.button(button_title, key=f"button_{idx}_{button_title}"):
st.write(f"After clicking {button_title}")
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.