I have a button with an on_click() to run a function which executes a query. It seems the on_click() is triggered when the parameters change, even if the button is not clicked. Example below - when queryText is changed via a text_area control, the on_click() function is executed.
queryText = st.sidebar.text_area("SQL to execute:", value="", height=3, max_chars=None )
if queryText:
# issue - on_click executes when queryText is changed , even if not clicked
btnResult= st.sidebar.button('Run', key='RunBtn', help=None, on_click=runQuery(queryText,False), args=None, kwargs=None)
if btnResult:
st.sidebar.text('Button pushed')
Based on your simplified example I donât think you should use state for this. I actually think you just need to use a form, that collects the SQL query and then has a form_submit_button that runs the typed query:
with st.sidebar.form("Input"):
queryText = st.text_area("SQL to execute:", height=3, max_chars=None)
btnResult = st.form_submit_button('Run')
if btnResult:
st.sidebar.text('Button pushed')
# run query
st.write(queryText)
In my token example, I simply write the query to the page but you would be able to actually send the queryText to get the data.
Let me know if this solves your issue! Happy Streamlit-ing
Marisa
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.