Streamlit session state and button

Viewed 29

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)
1 Answers

Solution: remove the “()” after the onClickFunction.

Related