Summary
The app has an input area to type text. When the submit button is clicked then the user input text gets written in the screen with the text appearing in the text area. So the user can input new text in the text area and can see the output. It works fine. But there are two buttons as examples for the users. When these buttons are clicked then the text of the button gets written in the screen along with the text area. But when I type something new and click the submit button then the app goes back to the initial state and does not output anything.
Steps to reproduce
Code snippet:
import streamlit as st
cont1 = st.empty()
with cont1.container():
prompt = st.text_area("Text",placeholder="prompt",key='promptKey',label_visibility='hidden')
submit_button = st.button('Submit ▶')
cont2 = st.empty()
with cont2.container():
sample_question = '<p style="font-family:sans-serif; color:Black; font-size: 18px; position: relative; top: 20px">Examples</p>'
st.markdown(sample_question, unsafe_allow_html=True)
st.markdown("""<hr style="height:5px;border:none;color:#333;background-color:#333;" /> """, unsafe_allow_html=True)
col1,col2 = st.columns(2)
with col1:
buttonName1 = "Hello!"
button1 = st.button(buttonName1)
with col2:
buttonName2 = "How are you?"
button2 = st.button(buttonName2)
def helpButtons(buttonName):
cont1.empty()
cont2.empty()
buttonPrompt = st.text_area("",value=buttonName)
submit_button3 = st.button('Submit',key='s3')
st.write(buttonPrompt)
if submit_button3:
cont1.empty()
cont2.empty()
submitPrompt = st.text_area("", value=buttonPrompt)
submit_button4 = st.button('Submit',key='s4')
st.write(submitPrompt)
if prompt:
cont1.empty()
cont2.empty()
prompt = st.text_area("",value=prompt)
submit_button2 = st.button('Submit')
st.write(prompt)
else:
if button1 | button2:
if button1:
helpButtons(buttonName=buttonName1)
elif button2:
helpButtons(buttonName=buttonName2)
Expected behavior:
When the example button “Hello!” is pressed then “Hello” gets outputted in the screen with the text area having the text “Hello!”. Then when I change the text to “Hey!” from “Hello!” and click the submit button then the output will be “Hey!”
Actual behavior:
When the example button “Hello!” is pressed then “Hello” gets outputted in the screen with the text area having the text “Hello!”. Then when I change the text to “Hey!” from “Hello!” and click the submit button then the app returns to the initial state (like reloads the homepage) and there is no output of the text “Hey!”
Debug info
- Streamlit version: 1.17.0
- Python version: 3.9.13
- Browser version: Microsoft Edge (Version 109.0.1518.69 (64-bit))
Any help is appreciated, thank you!