Hello I am using ag-grid package to show my dataframe in Streamlit app
Can you please guide us, how we can add custom_css to the ag-grid tables ?
Ex - I want to change ‘blue’ color to the ‘red’ in ag-grid table, I tried the following code, but it didn’t
work.
mrityunjay’s answer is correct I believe, but I couldn’t get it to work (perhaps because of styled quotes). If you want to try for yourself, here is a full script for generating an AgGrid table with custom CSS. This seems to work best when the theme parameter is not set:
import streamlit as st
import pandas as pd
import numpy as np
from st_aggrid import AgGrid
from st_aggrid import GridUpdateMode, JsCode
from st_aggrid.grid_options_builder import GridOptionsBuilder
#Define some data
cat_data = {'Cat': ['Fluffy', 'Whiskers', 'Simba', 'Nala', 'Oliver', 'Charlie', 'Max', 'Lucy', 'Mittens', 'Daisy'],
'Frequency of Grooming': np.random.randint(low=1, high=7, size=10),
'Duration of Grooming (minutes)': np.random.randint(low=5, high=30, size=10),
'Method': ['Licking', 'Brushing', 'Licking', 'Brushing', 'Licking', 'Brushing', 'Licking', 'Brushing', 'Licking', 'Brushing']}
cat_df = pd.DataFrame(cat_data)
#Define custom CSS
custom_css = {
".ag-row-hover": {"background-color": "red !important"},
".ag-header-cell-label": {"background-color": "orange !important"}
}
#Build Table
gd = GridOptionsBuilder.from_dataframe(cat_df)
gridOptions = gd.build()
table = AgGrid(
cat_df
custom_css=custom_css,
allow_unsafe_jscode=True
)
I have the row-hover working but how do you get both row and column hover to work?
Streamlit AgGrid is great but the documentation is geared for JavaScript. It looks like I will need to learn how to blend the Javascript into the streamlit code.