KJA
KJA

Reputation: 333

Streamlit 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:
  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)

Upvotes: 0

Views: 1607

Answers (1)

KJA
KJA

Reputation: 333

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

Upvotes: 1

Related Questions