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