Skip to content

Instantly share code, notes, and snippets.

@asaini
Created July 13, 2021 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaini/018d2c7e485dba323b9af02682e101cf to your computer and use it in GitHub Desktop.
Save asaini/018d2c7e485dba323b9af02682e101cf to your computer and use it in GitHub Desktop.
Blog code 1
import streamlit as st
st.title('Counter Example')
# Streamlit runs from top to bottom on every iteraction so
# we check if `count` has already been initialized in st.session_state.
# If no, then initialize count to 0
# If count is already initialized, don't do anything
if 'count' not in st.session_state:
st.session_state.count = 0
# Create a button which will increment the counter
increment = st.button('Increment')
if increment:
st.session_state.count += 1
# A button to decrement the counter
decrement = st.button('Decrement')
if decrement:
st.session_state.count -= 1
st.write('Count = ', st.session_state.count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment