I have reviewed my code, and it runs correctly. However, when I attempt to move the container from col1 to col2, or vice versa, or if I move any container using the mouse to a different column, I encounter an error: IndexError: pop index out of range at the line of code apply_move(event, st.session_state). Please examine my code and the error, and provide a suitable solution along with the corrected code.
import streamlit as st
from streamlit_dnd import dnd, apply_move
import pandas as pd
st.set_page_config(layout=“wide”)
# Initialize 5 dataframes in session state
if “dfs” not in st.session_state:
st.session_state.dfs = { "df1": pd.DataFrame({"Data": \["Item A", "Item B"\]}), "df2": pd.DataFrame({"Data": \["Item C", "Item D"\]}), "df3": pd.DataFrame({"Data": \["Item E", "Item F"\]}), "df4": pd.DataFrame({"Data": \["Item G", "Item H"\]}), "df5": pd.DataFrame({"Data": \["Item I", "Item J"\]}), }if “mdfs” not in st.session_state:
st.session_state.mdfs = { "mdf1": pd.DataFrame({"Data": \["Item A", "Item B"\]}), "mdf2": pd.DataFrame({"Data": \["Item C", "Item D"\]}), "mdf3": pd.DataFrame({"Data": \["Item E", "Item F"\]}), "mdf4": pd.DataFrame({"Data": \["Item G", "Item H"\]}), "mdf5": pd.DataFrame({"Data": \["Item I", "Item J"\]}), }if “my_variable” not in st.session_state:
st.session_state\["my_variable"\] = "Initial Value"# 2. Create columns
col1, col2 = st.columns(2 ,border=True)
# 3. Render containers in columns
with col1:
st.subheader("Right Column") with st.container(border=True, key="right"): for df_key, df_val in st.session_state.dfs.items(): with st.container(key=f"right\_{df_key}", border=True): st.write(f"### {df_key.upper()}") st.dataframe(df_val)with col2:
st.subheader("mfaRight Column") with st.container(border=True, key="mright"): for df_key, df_val in st.session_state.mdfs.items(): with st.container(key=f"mright\_{df_key}", border=True): st.write(f"### {df_key.upper()}") st.dataframe(df_val)# 4. Handle Drag and Drop
event = dnd(“right”, “mright”)
if event is not None:
apply_move(event, st.session_state) st.rerun()
error :
IndexError: pop index out of range
File “D:\pyff\dndtry.py”, line 79, in
apply_move(event, st.session_state)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\user\AppData\Local\Programs\Python\Python314\Lib\site-packages\streamlit_dnd\_init_.py”, line 270, in apply_move
item = src.pop(event.from_index)
