Session state and button

Hello,

Does anyone know how the code below could be changed so that the print only happens when the button “Run” is clicked? Now the print is performed every time “inp” is changed.

import streamlit as st

inp = st.number_input(“inp”, min_value=0, max_value=10, step=1, value=10)

if ‘click’ not in st.session_state:
st.session_state.click = False

def onClickFunction():
st.session_state.click = True
st.session_state.out = inp

runButton = st.button(“Run”,
on_click=onClickFunction())

if st.session_state.click:
st.write(“out”, st.session_state.out)

Hello Kaaja,

The only thing you need to do is to remove the “()” after the onClickFunction.
So, like this:
runButton = st.button(‘Run’, on_click=onClickFunction)

Thanks @halfspring :slight_smile: