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}")