Streamlit AgGrid

1.2.1.post2 · active · verified Sat Apr 11

Streamlit-AgGrid is an active Python library that provides a feature-rich implementation of the Ag-Grid JavaScript library as a Streamlit component. It enables developers to create sophisticated, interactive data tables within their Streamlit applications, offering functionalities such as advanced filtering, sorting, inline cell editing, row grouping, and custom cell rendering. The library, currently at version 1.2.1.post2, maintains an active release cadence with frequent updates and bug fixes, typically every few months.

Warnings

Install

Imports

Quickstart

This quickstart example demonstrates how to display a Pandas DataFrame using `streamlit-aggrid` with basic interactivity, including editable columns and row selection. It uses `GridOptionsBuilder` for customization and retrieves the `selected_rows` and potentially `edited data` from the grid's response.

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

st.set_page_config(layout='wide')

# Create a sample DataFrame
data = {
    'col1': [1, 2, 3, 4, 5],
    'col2': ['A', 'B', 'C', 'D', 'E'],
    'col3': [10.1, 20.2, 30.3, 40.4, 50.5],
    'col4': [True, False, True, False, True]
}
df = pd.DataFrame(data)

st.subheader('Basic Interactive AgGrid Table')

# Configure grid options
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_column('col1', header_name='Column One', editable=True)
gb.configure_column('col2', header_name='Column Two', editable=True)
gb.configure_selection(selection_mode='multiple', use_checkbox=True)

grid_options = gb.build()

# Display the AgGrid component
grid_response = AgGrid(
    df,
    gridOptions=grid_options,
    data_return_mode=DataReturnMode.AS_INPUT,
    update_mode=GridUpdateMode.MODEL_CHANGED,
    fit_columns_on_grid_load=True,
    height=350,
    width='100%',
    allow_unsafe_jscode=True, # Required for some advanced customizations like JsCode
    enable_enterprise_modules=False # Set to True if using Ag-Grid Enterprise features and have a license
)

st.subheader('Selected Rows')
if grid_response['selected_rows']:
    st.write(pd.DataFrame(grid_response['selected_rows']))

st.subheader('Edited Data (if any)')
if grid_response['data'] is not None:
    st.write(grid_response['data'])

view raw JSON →