Created
July 13, 2021 19:19
-
-
Save asaini/018d2c7e485dba323b9af02682e101cf to your computer and use it in GitHub Desktop.
Blog code 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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