Here’s my attempt to make a fully-complete standalone version of your script, and with the amount of data I used, it didn’t show any lag at all. What does disc.timer
do?
from dataclasses import dataclass
import streamlit as st
# dummy
def text_with_hover(text, hover):
st.write(text)
@dataclass
class Line:
name: str
line: dict
x: str
@dataclass
class Annotation:
name: str
data = {
"fig_base": {
"data": [
Line("line1", {"color": "#000"}, "abc"),
Line("line2", {"color": "#080"}, "abc"),
Line("line3", {"color": "#008"}, "abc"),
Line("line4", {"color": "#880"}, "abc"),
Line("line5", {"color": "#808"}, "abc"),
Line("line6", {"color": "#088"}, "abc"),
Line("line7", {"color": "#888"}, "abc"),
Line("line8", {"color": "#000"}, "abc"),
Line("line9", {"color": "#080"}, "abc"),
Line("line10", {"color": "#008"}, "abc"),
],
"layout": {
"annotations": [
Annotation("anno1"),
Annotation("anno2"),
Annotation("anno3"),
Annotation("anno4"),
Annotation("anno5"),
Annotation("anno6"),
Annotation("anno7"),
]
},
}
}
st.session_state["fig_base"] = data["fig_base"]
def display_options_main():
with st.expander("Anzeigeoptionen", False):
with st.form("Anzeigeoptionen"):
# columns
col_vis_1, col_vis_2, col_fill, col_anno = st.columns(4)
# change color picker
st.markdown(
"""
<style>
div.css-1me30nu {
gap: 0.5rem;
}
div.css-96rroi {
display: flex;
flex-direction: row-reverse;
align-items: center;
justify-content: flex-end;
line-height: 1.6;
}
div.css-96rroi > label {
margin-bottom: 0px;
padding-left: 8px;
font-size: 1rem;
}
div.css-96rroi > div {
height: 20px;
width: 20px;
vertical-align: middle;
}
div.css-96rroi > div > div {
height: 20px;
width: 20px;
padding: 0px;
vertical-align: middle;
}
</style>
""",
unsafe_allow_html=True,
)
# Ăśberschriften
with col_vis_1:
text_with_hover("Anzeigen", "Linien, die angezeigt werden sollen")
with col_vis_2:
text_with_hover("Farbe", "Linienfarbe wählen")
with col_fill:
text_with_hover(
"FĂĽllen", "Linien, die zur x-Achse ausgefĂĽllt werden sollen"
)
with col_anno:
text_with_hover("Maximum", "Maxima als Anmerkung mit Pfeil")
# Check Boxes for line visibility, fill and color
for line in st.session_state["fig_base"]["data"]:
l_n = line.name
l_c = line.line["color"]
if (
len(line.x) > 0
and "hline" not in l_n
and l_n is not None
and l_c is not None
):
with col_vis_1:
st.checkbox(label=l_n, value=True, key="cb_vis_" + l_n)
with col_vis_2:
st.color_picker(
label=l_n,
value=l_c,
key="cp_" + l_n,
)
with col_fill:
st.checkbox(label=l_n, value=False, key="cb_fill_" + l_n)
# Check Boxes for annotations
for anno in [
anno.name
for anno in st.session_state["fig_base"]["layout"]["annotations"]
if "hline" not in anno.name
]:
with col_anno:
st.checkbox(label=anno, value=False, key="cb_anno_" + anno)
st.markdown("###")
but_upd_main = st.form_submit_button("Knöpfle")
st.markdown("###")
return but_upd_main
display_options_main()