I found some problems when I tried to use a text_input inside a button.
This is an example:
import streamlit as st
header = st.header('Text_input APP')
button1 = st.button('Click here')
if button1:
text = st.text_input('Write some texte', value=' ')
st.write('Text: ', text)
When I click on the button1 the text_input box appears and I write some text. However, when I press Enter to display what I wrote, the “window” closes and it goes to the app’s initial page.
Is there any way to solve this problem?
Thanks,
The button’s True state happens only when you click it. After the text box edit is applied the app reruns and the button will now be in the False state, so the text box will not display until the button is clicked again. What you want is sticky True/False state between reruns, so you should use a checkbox instead. (Streamlit reruns top to bottom every time a widget value changes.)
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.