streamlit

Форк
0
/
st_slider.py 
80 строк · 2.4 Кб
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
from datetime import date
16

17
import streamlit as st
18
from streamlit import runtime
19

20
s1 = st.sidebar.slider("Label A", 0, 12345678, 12345678)
21
st.sidebar.write("Value A:", s1)
22

23
r1 = st.sidebar.slider("Range A", 10000, 25000, [10000, 25000])
24
st.sidebar.write("Range Value A:", r1)
25

26
with st.sidebar.expander("Expander", expanded=True):
27
    s2 = st.slider("Label B", 10000, 25000, 10000)
28
    st.write("Value B:", s2)
29

30
    r2 = st.slider("Range B", 10000, 25000, [10000, 25000])
31
    st.write("Range Value B:", r2)
32

33
w1 = st.slider("Label 1", 0, 100, 25, 1)
34
st.write("Value 1:", w1)
35

36
w2 = st.slider("Label 2", 0.0, 100.0, (25.0, 75.0), 0.5)
37
st.write("Value 2:", w2)
38

39
w3 = st.slider(
40
    "Label 3 - This is a very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long label",
41
    0,
42
    100,
43
    1,
44
    1,
45
)
46
st.write("Value 3:", w3)
47

48
w4 = st.slider("Label 4", 10000, 25000, 10000, disabled=True)
49
st.write("Value 4:", w4)
50

51
w5 = st.slider("Label 5", 0, 100, 25, 1, label_visibility="hidden")
52
st.write("Value 5:", w5)
53

54
w6 = st.slider("Label 6", 0, 100, 36, label_visibility="collapsed")
55
st.write("Value 6:", w6)
56

57
dates = st.slider(
58
    "Label 7",
59
    min_value=date(2019, 8, 1),
60
    max_value=date(2021, 6, 4),
61
    value=(date(2019, 8, 1), date(2019, 9, 1)),
62
)
63
st.write("Value 7:", dates[0], dates[1])
64

65
if runtime.exists():
66

67
    def on_change():
68
        st.session_state.slider_changed = True
69

70
    st.slider(
71
        "Label 8",
72
        min_value=0,
73
        max_value=100,
74
        value=25,
75
        step=1,
76
        key="slider8",
77
        on_change=on_change,
78
    )
79
    st.write("Value 8:", st.session_state.slider8)
80
    st.write("Slider changed:", "slider_changed" in st.session_state)
81

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

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

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

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