Session state and button


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: = False

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

runButton = st.button(“Run”,

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: