Summary
I have a very strange behaviour. Only on the first run of the code and with the first change in the st.data_editor - e.g. in column B, you recognize., that the page flickers exactly one time. After the first run, it never appears again.
Steps to reproduce
Code snippet:
import pandas as pd
import streamlit as st
st.set_page_config(layout="wide", page_title="Test")
# Cache data from mysql database
@st.cache_data
def run_query():
# Here is normally my SQL query
df_sql=pd.DataFrame({"A":['1','2','3'],"B":['2','3','4'],"C":['3','4','5']})
return df_sql
# Initialize session states for further needs
if "df" not in st.session_state:
st.session_state['df'] = run_query()
if "df_ed" not in st.session_state:
st.session_state["df_ed"] = st.session_state["df"]
# Create columns
col1, col2 = st.columns([8,2])
# Create data_editor @ column 1
st.session_state["df_ed"]=col1.data_editor(st.session_state['df'],hide_index=True, use_container_width=True)
With this code, everything works:
import pandas as pd
import streamlit as st
st.set_page_config(layout="wide", page_title="Test")
# Cache data from mysql database
@st.cache_data
def run_query():
# Here is normally my SQL query
df_sql=pd.DataFrame({"A":['1','2','3'],"B":['2','3','4'],"C":['3','4','5']})
return df_sql
# Initialize session states for further needs
if "df" not in st.session_state:
st.session_state['df'] = run_query()
if "df_ed" not in st.session_state:
st.session_state["df_ed"] = st.session_state["df"]
# Create data_editor @ column 1
st.session_state["df_ed"]=st.data_editor(st.session_state['df'],hide_index=True, use_container_width=True)
Expected behavior:
No flicker with first run.
Actual behavior:
The window flickers one time in the first run and with the first edit in the table. The problem has something to do with st.columns. If I don´t use st.columns (col1) and call st.data_editor instead of col1.data_editor, everything is fine. But I need these columns both for other purposes.
What is the problem in the first example?
Debug info
- Streamlit version: 1.27.2
- Python version:3.9.17
- OS version: Win10
- Browser version: Mozilla 115.3.1esr