I would like to place the st.error message directly below the input box. However, I cannot seem to place it there in any way. It always appears above the input message. I tried using st.empty and container to place it, but that did not work. Thanks in advance
Here is my code
import streamlit as st
st.title("Welcome to compute Request")
if 'something' not in st.session_state:
st.session_state.something = ''
if 'widget' not in st.session_state:
st.session_state.widget = ''
input_value = st.text_input('Something', key='widget')
def submit():
if not input_value:
st.error('Please enter a value')
st.session_state.something = ''
else:
st.session_state.widget = ''
st.session_state.something = input_value
st.button('Submit', on_click=submit)
st.write(f'Last submission: {st.session_state.something}')
print(st.session_state.something)
import streamlit as st
if 'something' not in st.session_state:
st.session_state.something = ''
st.title("Welcome to compute Request")
input_value = st.text_input('Something', placeholder='Please enter a value')
if input_value == 'quit':
st.error("You can't quit right now")
elif input_value != '' and input_value != 'quit':
st.session_state.something = input_value
st.write(f'Last submission: {st.session_state.something}')
import streamlit as st
st.title("Welcome to compute Request")
if 'something' not in st.session_state:
st.session_state.something = ''
if 'widget' not in st.session_state:
st.session_state.widget = ''
input_value = st.text_input('Something', key='widget')
def submit():
if not input_value:
st.session_state.widget = ''
st.session_state.something = "Write Something"
return True
else:
st.session_state.widget = ''
st.session_state.something = input_value
return False
x = st.button('Submit', on_click=submit)
if x:
st.error('Please enter a value')
else:
st.write(f'Last submission: {st.session_state.something}')
print(st.session_state.something)
The error is shown even when there was some input. The idea was to clear the widget input, but no error should be shown if there is some input. If the input is empty, then the error should be shown
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.