streamlit

Форк
0
/
st_button.py 
76 строк · 2.3 Кб
1
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
import streamlit as st
16
from streamlit import runtime
17

18
# st.session_state can only be used in streamlit
19
if runtime.exists():
20

21
    def on_click(x, y):
22
        if "click_count" not in st.session_state:
23
            st.session_state.click_count = 0
24

25
        st.session_state.click_count += 1
26
        st.session_state.x = x
27
        st.session_state.y = y
28

29
    i1 = st.button(
30
        "button 1", key="button", on_click=on_click, args=(1,), kwargs={"y": 2}
31
    )
32
    st.write("value:", i1)
33
    st.write("value from state:", st.session_state["button"])
34

35
    button_was_clicked = "click_count" in st.session_state
36
    st.write("Button was clicked:", button_was_clicked)
37

38
    if button_was_clicked:
39
        st.write("times clicked:", st.session_state.click_count)
40
        st.write("arg value:", st.session_state.x)
41
        st.write("kwarg value:", st.session_state.y)
42

43
i2 = st.checkbox("reset button return value")
44

45
i3 = st.button("button 2 (disabled)", disabled=True)
46
st.write("value 2:", i3)
47

48
i4 = st.button("button 3 (primary)", type="primary")
49
st.write("value 3:", i4)
50

51
i5 = st.button("button 4 (primary + disabled)", type="primary", disabled=True)
52
st.write("value 4:", i5)
53

54
st.button("button 5 (container_width)", use_container_width=True)
55

56
st.button(
57
    "button 6 (container_width + help)", use_container_width=True, help="help text"
58
)
59

60
st.button("_button 7_ (**styled** :green[label])")
61

62
cols = st.columns(3)
63

64
# Order of conn_types matters to preserve the order in st_button.spec.js and the snapshot
65
conn_types = [
66
    "snowflake",
67
    "bigquery",
68
    "huggingface",
69
    "aws_s3",
70
    "http_file",
71
    "postgresql",
72
    "gsheets",
73
    "custom",
74
]
75
for i in range(len(conn_types)):
76
    cols[i % 3].button(conn_types[i], use_container_width=True)
77

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.