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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.