forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathst_button.py
81 lines (64 loc) · 2.44 KB
/
st_button.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import streamlit as st
from streamlit import runtime
# st.session_state can only be used in streamlit
if runtime.exists():
def on_click(x, y):
if "click_count" not in st.session_state:
st.session_state.click_count = 0
st.session_state.click_count += 1
st.session_state.x = x
st.session_state.y = y
i1 = st.button(
"button 1", key="button", on_click=on_click, args=(1,), kwargs={"y": 2}
)
st.write("value:", i1)
st.write("value from state:", st.session_state["button"])
button_was_clicked = "click_count" in st.session_state
st.write("Button was clicked:", button_was_clicked)
if button_was_clicked:
st.write("times clicked:", st.session_state.click_count)
st.write("arg value:", st.session_state.x)
st.write("kwarg value:", st.session_state.y)
i2 = st.checkbox("reset button return value")
i3 = st.button("button 2 (disabled)", disabled=True)
st.write("value 2:", i3)
i4 = st.button("button 3 (primary)", type="primary")
st.write("value 3:", i4)
i5 = st.button("button 4 (primary + disabled)", type="primary", disabled=True)
st.write("value 4:", i5)
st.button("button 5 (container_width)", use_container_width=True)
st.button(
"button 6 (container_width + help)", use_container_width=True, help="help text"
)
st.button(
":material/search: _button 7_ (**styled** :green[label]) :material/arrow_forward:"
)
st.button("Like Button", icon=":material/thumb_up:")
st.button("Star Button", icon="⭐")
cols = st.columns(3)
# Order of conn_types matters to preserve the order in st_button.spec.js and the snapshot
conn_types = [
"snowflake",
"bigquery",
"huggingface",
"aws_s3",
"http_file",
"postgresql",
"gsheets",
"custom",
]
for i in range(len(conn_types)):
cols[i % 3].button(conn_types[i], use_container_width=True)