I wonder if is there a way to style dataframe or data_editor based on the selected cell.
I want to highlight the row which the cell is selected to make it easier for the user to follow the row on many columns dataframes/data_editors
One popular solution is to use the streamlit-aggrid library, which is an advanced wrapper around the AG-Grid. It offers more interactive capabilities, including cell selection and styling.
First, you need to install this package if you haven’t already:
pip install streamlit-aggrid
Here’s a simple example:
import streamlit as st
from st_aggrid import AgGrid, GridOptionsBuilder
import pandas as pd
df = pd.DataFrame({'A': range(1, 6), 'B': range(10, 15)})
# AG Grid Options
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_selection('single', use_checkbox=True, rowMultiSelectWithClick=True)
grid_options = gb.build()
grid_response = AgGrid(df, grid_options=grid_options, fit_columns_on_grid_load=True)
selected = grid_response['selected_rows']
if selected:
selected_row = selected[0]
st.write("Selected Row:", selected_row)
If the streamlit-aggrid library doesn’t meet your needs, another approach is to create a custom Streamlit component.
Let me know if you might require any further assistance!
Definitely AgGrid is awesome and it would solve all issues, but I had some trouble in putting it into action when I fed it a 4k row dataframe. It simply stopped rendering. If I give it a df.head(20) there’s no problem, so I think the dataframe is too big for it deal with.
Is there a workaround to improve its performance?
Thank you for your assistance!
Regards,
Renato Moraes
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.