-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (30 loc) · 1.06 KB
/
app.py
File metadata and controls
40 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import streamlit as st
# Set up session state variables
if "ten_x" not in st.session_state:
# ten_x mode changes our buttons to increment and decrement by 10 instead of by 1
st.session_state.ten_x = 0
if "count" not in st.session_state:
st.session_state.count = 0
# Set up callbacks for inputs
def increment():
st.session_state.count += 10 if st.session_state.ten_x else 1
def decrement():
st.session_state.count -= 10 if st.session_state.ten_x else 1
if st.session_state.count < 0:
# Minimum count value is zero
st.session_state.count = 0
# Write to page
with st.expander("Options") as options:
# The key of the checkbox (ten_x) will automatically be added to the session state
st.checkbox("10x mode", key="ten_x", value=st.session_state.ten_x)
st.write(f"Total count is {st.session_state.count}")
st.button(
f"plus {'10' if st.session_state.ten_x else '1'}",
key="increment",
on_click=increment,
)
st.button(
f"minus {'10' if st.session_state.ten_x else '1'}",
key="decrement",
on_click=decrement,
)