Don't reconnect to the server

hi all.
I want to write a simple program with entering data through streamlit and sending this data to CasparCG. but when editing the data, I reconnect to the CasparCG server. how can i solve this problem?
short video

import streamlit as st
import pandas as pd
from amcp_pylib.core import Client

if st.checkbox("ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒΡΡ"):
    connection = Client()
    connection.connect("127.0.0.1", 5250)
    st.success("Π‘ΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅ установлСно")
    is_connected = True

@st.cache_data
def load_data(uploaded_file):
    df = pd.read_excel(uploaded_file)
    return df

placeholder = st.empty()
with placeholder.container():
    tab1, tab2 = st.tabs(["Π Π΅Π΄Π°ΠΊΡ‚ΠΎΡ€", "Π’ΠΈΡ‚Ρ€Ρ‹"])
    with tab1:
        col1, col2 = st.columns((3, 7))
        with col1:
            uploaded_file = st.file_uploader(
                "Choose a Excel file", type="xlsx", accept_multiple_files=False
            )

        with col2:
            if uploaded_file is not None:
                df = load_data(uploaded_file)
                # df = pd.read_excel(uploaded_file)
            else:
                df = pd.DataFrame(
                    [
                        {
                            "Имя + Ѐамилия / НикнСйм": "",
                            "instagtam/telegram/youtube": "",
                            "Команда/Π°ΠΌΠΏΠ»ΡƒΠ°": "",
                            "Π’Ρ‹Π±Ρ€Π°Ρ‚ΡŒ": False,
                        },
                    ]
                )
            
            # print(df["Команда/Π°ΠΌΠΏΠ»ΡƒΠ°"].unique())
            teams_temp = df["Команда/Π°ΠΌΠΏΠ»ΡƒΠ°"].unique()
            teams_new = []
            for team1 in teams:
                if team1 in teams_temp:
                    continue
                else:
                    teams_new.append(team1)
            df["Команда/Π°ΠΌΠΏΠ»ΡƒΠ°"] = (
                df["Команда/Π°ΠΌΠΏΠ»ΡƒΠ°"].astype("category").cat.add_categories(teams_new)
            )
            edited_df = st.experimental_data_editor(df, num_rows="dynamic", height=600)
            category = edited_df["Команда/Π°ΠΌΠΏΠ»ΡƒΠ°"].unique()

        with col1:
            # buffer to use for excel writer
            buffer = io.BytesIO()

            # download button 2 to download dataframe as xlsx
            with pd.ExcelWriter(buffer, engine="xlsxwriter") as writer:
                edited_df.to_excel(writer, sheet_name="Sheet1", index=False)
                # writer.close()

                download2 = st.download_button(
                    label="Download data as Excel",
                    data=buffer,
                    file_name="mfl_titles.xlsx",
                    mime="application/vnd.ms-excel",
                )

    with tab2:
        col1, col2 = st.columns((1, 9))
        with col1:
            option = st.selectbox("Команда", sorted(category))
        with col2:
            edited_df = st.experimental_data_editor(
                edited_df.loc[edited_df["Команда/Π°ΠΌΠΏΠ»ΡƒΠ°"] == option],
                num_rows="fixed",
                height=600,
            )


Thank you

Hi there,

Thanks for sharing your question with the community!

Please check out our guidelines on how to post an effective question here and update your post to include a runnable code snippet so community members can make helpful suggestions :blush: