I've the following code def drawBtn(): option= ... st.button("Find", on_click= onSearch, args= [option]) def onSearch(opt): # do something and then... st.success("Done!") drawBtn() The problem here is that the message "Done" is insert at the top of the page instead of at the end. This problem appear only if i use on_click function. If i change it with if st.button(...): it work as i expect Why using on_click function seems like moving the pointer of the page at the beginning? Searching on the internet i saw always function that set only variables in st.session_state. So another question is: can I do something else inside a on_click function different to set session_state variables? Because If I try to add something else, that content is drawn always at the beginning of the page
Drop files here
or click to upload
import streamlit as st
def drawBtn():
option = st.text_input('Enter an option:')
st.button('Find', on_click=onSearch, args=[option])
def onSearch(opt):
# do something with the option
if opt:
# Simulating some processing
st.session_state.processed_option = f'Processed: {opt}'
# Providing feedback
st.success('Done!')
else:
st.warning('Please enter a valid option.')
drawBtn()
if 'processed_option' in st.session_state:
st.write(st.session_state.processed_option)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?