AttributeError: FULL

Hi

I“m new on this part, so bear with me.

I’ve honestly tried chat GPT but here it runs into a challenge it couldn’t handle.

Made other code by following an interesting review via the youtube channel Code is fun (Sven) and it works fine.

But to the code I now want to add streamlit_aggrid and despite several attempts I can’t get it to work. What is correct attribute?

Error code is as follows: (Know it’s wrong but tried with JSON, FORM_FILL and VALUE)

AttributeError: FULL

Traceback:

File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
    exec(code, module.__dict__)File "/Users/install/Library/Mobile Documents/com~apple~CloudDocs/TK iCloud Drive/TEST/Kunder/app.py", line 60, in <module>
    data_return_mode=DataReturnMode.FULL
                     ^^^^^^^^^^^^^^^^^^^File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/enum.py", line 789, in __getattr__
    raise AttributeError(name) from None

Code snippet:

import pandas as pd
import streamlit as st
import streamlit.components.v1 as components
from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode

st.set_page_config(page_title="Sales Dashboard", layout="wide")

df = pd.read_excel(
    io='Kunder.xlsx',
    engine='openpyxl',
    sheet_name='Kunder',
    skiprows=1,
    usecols='A:G',
    nrows=2000
)

# ----- SIDEBAR -----
st.sidebar.header("Please Filter Here:")
all_option = ["All"]
sales_rep = st.sidebar.selectbox(
    "Select Sales_Rep:",
    options=all_option + list(df["Sales_Rep"].unique()),
    index=0
)

head_customer = st.sidebar.selectbox(
    "Select Head_Customer_Name:",
    options=all_option + list(df["Head_Customer_Name"].unique()),
    index=0
)

if sales_rep == "All" and head_customer == "All":
    df_selection = df.copy()
elif sales_rep != "All" and head_customer != "All":
    df_selection = df.query("Sales_Rep == @sales_rep and Head_Customer_Name == @head_customer")
elif sales_rep == "All":
    df_selection = df.query("Head_Customer_Name == @head_customer")
else:
    df_selection = df.query("Sales_Rep == @sales_rep")

# Define AgGrid configuration
gb = GridOptionsBuilder.from_dataframe(df_selection)
gb.configure_default_column(groupable=True, value=True, enableRowGroup=True, aggFunc='sum', editable=True)
gridOptions = gb.build()

# Render AgGrid
components.html(
    AgGrid(
        df_selection,
        gridOptions=gridOptions,
        width='100%',
        height='500px',
        data_return_mode=DataReturnMode.FULL
    ).get_html(),
    height=800
)

From the docs:

  • data_return_mode –
    Defines how the data will be retrieved from components client side. One of:

    • DataReturnMode.AS_INPUT → Returns grid data as inputed. Includes cell editions
    • DataReturnMode.FILTERED → Returns filtered grid data, maintains input order
    • DataReturnMode.FILTERED_AND_SORTED → Returns grid data filtered and sorted

Thanks Goyo

changed my code, but i seem to missunderstand something, i getting new error

Error is TypeError: Cannot set IFrame.srcdoc to AgGridReturn

Code i changed

Define AgGrid configuration

gb = GridOptionsBuilder.from_dataframe(df_selection)
gb.configure_default_column(groupable=True, value=True, enableRowGroup=True, aggFunc=ā€˜sum’, editable=True)
gridOptions = gb.build()

Render AgGrid

components.html(
AgGrid(
df_selection,
gridOptions=gridOptions,
width=ā€˜100%’,
height=ā€˜500px’,
data_return_mode=DataReturnMode.AS_INPUT
),
height=800
)

I guess you should be passing actual html to components.html. Maybe you should take a look at other examples of using AgGrid, what you are doing here feels a bit strange to me.

Try calling AgGrid() directly (remove the components.html around it).

Thanks ennui

It is working fine but i seem miss something (as i said I“m new on this part, so bear with me) still

Now i have both the aagrid but seems to still have the dataframe table under it

i add both a picture how it looks and the code under it

import pandas as pd
import streamlit as st
from st_aggrid import AgGrid, AgGridTheme

st.set_page_config(page_title=ā€œSales Dashboardā€, layout=ā€œwideā€)

df = pd.read_excel(
io=ā€˜Kunder.xlsx’,
engine=ā€˜openpyxl’,
sheet_name=ā€˜Kunder’,
skiprows=1,
usecols=ā€˜A:G’,
nrows=2000
)

----- SIDEBAR -----

st.sidebar.header(ā€œPlease Filter Here:ā€)
all_option = [ā€œAllā€]
sales_rep = st.sidebar.selectbox(
ā€œSelect Sales_Rep:ā€,
options=all_option + list(df[ā€œSales_Repā€].unique()),
index=0
)

head_customer = st.sidebar.selectbox(
ā€œSelect Head_Customer_Name:ā€,
options=all_option + list(df[ā€œHead_Customer_Nameā€].unique()),
index=0
)

if sales_rep == ā€œAllā€ and head_customer == ā€œAllā€:
df_selection = df.copy()
elif sales_rep != ā€œAllā€ and head_customer != ā€œAllā€:
df_selection = df.query(ā€œSales_Rep == @sales_rep and Head_Customer_Name == @head_customerā€)
elif sales_rep == ā€œAllā€:
df_selection = df.query(ā€œHead_Customer_Name == @head_customerā€)
else:
df_selection = df.query(ā€œSales_Rep == @sales_repā€)

grid_return = AgGrid(df_selection, editable=False, theme=AgGridTheme.STREAMLIT, height=2000)
new_df = pd.DataFrame(grid_return[ā€˜data’])

st.write(new_df)

That’s exactly what st.write(new_df) does. What else are you trying to achieve with that line of code?

I only want the table that is in the top with the st_aggrid and not the one under

Can you help me out what i“m doing wrong? Don“t want to see the table under the first table

Then delete the line that is displaying the second table st.write(new_df).