dear sir I am attempting to utilize five dataframes in streamlit_dnd for drag-and-drop functionality, allowing users to move them within Streamlit containers.
Please review the code I obtained from Google, as it is generating an error.
import streamlit as st
import pandas as pd
from streamlit_dnd import dnd, apply_move
# 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"\]}), }# Display each dataframe in a draggable container
container_key = “my_dnd_list”
with st.container(key=container_key, border=True):
for df_key, df_val in st.session_state.dfs.items(): with st.container(key=f"item\_{df_key}", border=True): st.write(f"### {df_key.upper()}") st.dataframe(df_val)# Handle drag-and-drop events
drop_event = dnd(container_key)
if drop_event:
apply_move(drop_event, st.session_state.dfs) st.rerun()
see error
KeyError: ‘my_dnd_list’
File “D:\pyff\dndwdf.py”, line 27, in
apply_move(drop_event, st.session_state.dfs)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\user\AppData\Local\Programs\Python\Python314\Lib\site-packages\streamlit_dnd\_init_.py”, line 267, in apply_move
src = lists[event.from_container]
~~~~~^^^^^^^^^^^^^^^^^^^^^^
please see my code and give the solution
best regards

