- Are you running your app locally or is it deployed? Locally
- Share the Streamlit and Python versions.
Python 3.11.5
streamlit==1.37.0
No errors just not understanding behaviour.
Issue:
Hello,
I’m new to streamlit.
I’m building a streamlit app and just laying the basic functionality (buttons, text boxes, etc…).
I want the user to only be able to give feedback once per submission (+1 or -1).
For this I’m using a st.session attribute: submitted to enable or disable feedback buttons.
I face a behavior that i do not understand when I submit text using ask button.
If I pressed +1, I’m allowed to repress +1 one more time (button not disabled).
If I pressed -1, I’m allowed to repress +1 or -1 one more time (buttons not disabled).
The buttons should be disabled if st.session.submitted is False.
The issue is mainly in st.session.submitted, it gets somehow reassigned to True again, despite one feedback button is pushed.
Can anyone help with this? I tried chatgpt and claude and both didn’t help.
import streamlit as st
import uuid
def print_log(*message):
print(*message, flush=True)
def main():
print_log("Starting the Course Assistant application")
st.title("Course Assistant")
# Session state initialization
if 'conversation_id' not in st.session_state:
st.session_state.conversation_id = str(uuid.uuid4())
print_log(f"New conversation started with ID: {st.session_state.conversation_id}")
if 'count' not in st.session_state:
st.session_state.count = 0
print_log("Feedback count initialized to 0")
if 'submitted' not in st.session_state:
st.session_state.submitted = False
# User input
user_input = st.text_input("Enter your question:")
if st.button("Submit"):
print_log(f"User submitted question: {user_input}")
st.write(f"Question submitted: {user_input}")
st.session_state.submitted = True
col1, col2 = st.columns(2)
with col1:
if st.button("+1", disabled=not st.session_state.submitted):
st.session_state.submitted = False
st.session_state.count += 1
print_log(f"Positive feedback received. New count: {st.session_state.count}")
with col2:
if st.button("-1", disabled=not st.session_state.submitted):
st.session_state.submitted = False
st.session_state.count -= 1
print_log(f"Negative feedback received. New count: {st.session_state.count}")
st.write(f"Current count: {st.session_state.count}")
if __name__ == "__main__":
main()