streamlit
69 строк · 2.6 Кб
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
15import streamlit as st
16
17sidebar = st.sidebar.expander("Expand me!")
18sidebar.write("I am in the sidebar")
19
20expander = st.expander("Collapse me!", expanded=True)
21expander.write("I can collapse")
22expander.slider("I don't get cut off")
23expander.button("I'm also not cut off (while focused)")
24
25collapsed = st.expander("_Expand_ **me**!")
26collapsed.write("I am already collapsed")
27
28st.expander("Empty expander")
29
30with st.expander("Expander with number input", expanded=True):
31# We deliberately use a list to implement this for the screenshot
32st.write("* Example list item")
33value = st.number_input("number", value=1.0, key="number")
34
35
36def update_value():
37st.session_state.number = 0
38
39
40update_button = st.button("Update Num Input", on_click=update_value)
41
42st.text(st.session_state.number)
43
44if st.button("Print State Value"):
45st.text(st.session_state.number)
46
47expander_long = st.expander(
48"Expand me! "
49"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum arcu nisl, tincidunt id "
50"orci id, condimentum cursus nunc. Nullam sed sodales ipsum, vel tincidunt dui. Etiam diam "
51"dolor, eleifend sit amet purus id, dictum aliquam quam.",
52expanded=True,
53)
54expander_long.write(
55"I can collapse. "
56"Integer et justo orci. In euismod posuere nulla ac maximus. Mauris tristique hendrerit "
57"placerat. Integer eu imperdiet ipsum. Praesent maximus pharetra est, ut ultrices ante "
58"molestie id. Nulla sollicitudin arcu orci, eget lobortis lacus ultricies eu. Ut suscipit est "
59"eget tellus laoreet faucibus. Nullam nec blandit felis. Nulla ullamcorper, justo eget "
60"consequat ultricies, nisi dolor lacinia mauris, eu lacinia ante nisi sit amet tortor."
61)
62
63collapsed_long = st.expander(
64"Expand me! "
65"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum arcu nisl, tincidunt id "
66"orci id, condimentum cursus nunc. Nullam sed sodales ipsum, vel tincidunt dui. Etiam diam "
67"dolor, eleifend sit amet purus id, dictum aliquam quam."
68)
69collapsed_long.write("I am already collapsed")
70