Summary
I need to load a csv as a dataframe into streamlit-aggrid. I have some code that changes the cell colors based on some condition and then I want to edit the cells in the dataframe and export it as a csv or excel file.
Steps to reproduce
Code snippet:
import os
import streamlit as st
import pandas as pd
import tqdm
from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode, JsCode
CSV_DIR_PATH = "../prace_files/"
file_list = []
for filename in tqdm.tqdm(os.listdir(CSV_DIR_PATH)):
if filename.endswith('.csv'):
file_list.append(filename)
df = pd.read_csv(CSV_DIR_PATH + file_list[0])
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_pagination(paginationAutoPageSize=True)
gb.configure_side_bar()
gb.configure_selection('multiple', use_checkbox=True, groupSelectsChildren="Group checkbox select children")
cellstyle_jscode = JsCode("""
function(params) {
if (params.data.year == 2011) {
return {
'color': 'red',
'backgroundColor': 'green'
}
} else {
return {
'color': 'black',
'backgroundColor': 'red'
}
}
};
""")
gb.configure_column("year", cellStyle=cellstyle_jscode)
gridOptions = gb.build()
grid_response = AgGrid(
df,
gridOptions=gridOptions,
data_return_mode=DataReturnMode.AS_INPUT,
update_mode=GridUpdateMode.MODEL_CHANGED,
fit_columns_on_grid_load=False,
theme='blue', # Add theme color to the table
enable_enterprise_modules=True,
height=850,
width='100%',
allow_unsafe_jscode=True,
)
new_df = grid_response['data']
selected = grid_response['selected_rows']
df = pd.DataFrame(selected)
Expected behavior:
I want to be able to edit the cells. But I cannot, can’t click into them, write or do anything with them with the current code. The colors don’t stay changed when I export the data to csv or excel.
Actual behavior:
Colors are being changed correctly based on the condition inside the browser view, but if i export it, the colors won’t stay changed.