streamlit

Форк
0
/
st_data_editor_input_data.py 
56 строк · 1.8 Кб
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 random
16

17
import numpy as np
18
import pandas as pd
19

20
import streamlit as st
21
from streamlit.type_util import DataFormat
22
from tests.streamlit.data_mocks import SHARED_TEST_CASES, TestCaseMetadata
23

24
np.random.seed(0)
25
random.seed(0)
26

27
st.set_page_config(layout="wide")
28

29
activate_dynamic_editing = st.toggle("Activate dynamic editing")
30
show_return_data = st.toggle("Show return data")
31

32
TEST_CASES = SHARED_TEST_CASES.copy()
33
TEST_CASES.append(
34
    (
35
        pd.DataFrame(
36
            np.random.randn(3, 3),
37
            columns=pd.MultiIndex.from_tuples(
38
                [("A", "foo"), ("A", "bar"), ("B", "foo")]
39
            ),
40
        ),  # Explicitly set the range index to have the same behavior across versions
41
        TestCaseMetadata(0, 2, DataFormat.PANDAS_DATAFRAME),
42
    ),
43
)
44

45
# # Render all test cases with st.data_editor:
46
for i, test_case in enumerate(TEST_CASES):
47
    data = test_case[0]
48
    data_format = str(test_case[1].expected_data_format)
49
    st.subheader(data_format)
50
    return_df_fixed = st.data_editor(
51
        data,
52
        key=f"data_editor-{i}",
53
        num_rows="dynamic" if activate_dynamic_editing else "fixed",
54
    )
55
    if show_return_data:
56
        st.dataframe(return_df_fixed)
57

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

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

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

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