添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I display a dataframe using AgGrid component. When I click on any column in the table to sort or filter it forces the app to re-run and clears all the output. How to fix this behaviour to allow users to interact with the table and see the output (e.g. sorted or filtered table)?

I specified reload_data = False parameter.
Please see below a code example.

# Import libraries
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid, JsCode
st.set_page_config(
    page_title="AgGrid Test"
# User input
with st.form('input'):
    text_input = st.text_area("Enter text here", height=350)  
    submit_button = st.form_submit_button(label="Extract data")    
# Extract metadata on submit 
if submit_button:
    df = pd.DataFrame(data = {'column1': ['a', 'b', 'c'], 'column2': [1,2,3]})
    AgGrid(df, reload_data = False)

Python==3.8.0
streamlit==1.11.1
streamlit-aggrid==0.3.2
Linux AWS EC2 instance Ubuntu 18.04.3 LTS
Chrome Version 103.0.5060.134 (Official Build) (64-bit)

Hmmm. I am not use, but I have some different options set than you and this problem doesn’t happen to me. Perhaps you can try running it as below and see if the problem persists?

def aggrid_interactive_table(df: pd.DataFrame): """Creates an st-aggrid interactive table based on a dataframe. Args: df (pd.DataFrame]): Source dataframe Returns: dict: The selected row options = GridOptionsBuilder.from_dataframe( df, enableRowGroup=True, enableValue=True, enablePivot=True options.configure_side_bar() options.configure_selection("single") selection = AgGrid( enable_enterprise_modules=True, gridOptions=options.build(), theme="light", update_mode=GridUpdateMode.MODEL_CHANGED, allow_unsafe_jscode=True, return selection selection = aggrid_interactive_table(df=tabledata)
  • fit_columns_on_grid_load : bool, optional
  • Will adjust columns to fit grid width on grid load, by default False
  • update_mode : GridUpdateMode, optional
  • UPDATE_MODE IS DEPRECATED. USE update_on instead.
  • Defines how the grid will send results back to streamlit.
  • either a string, one or a combination of:
  • GridUpdateMode.NO_UPDATE
  • GridUpdateMode.MANUAL
  • GridUpdateMode.VALUE_CHANGED
  • GridUpdateMode.SELECTION_CHANGED
  • GridUpdateMode.FILTERING_CHANGED
  • GridUpdateMode.SORTING_CHANGED
  • GridUpdateMode.MODEL_CHANGED
  • Thank you @Connor. When I add update_on=['cellValueChanged'] the table just keeps loading forever and never gets displayed. Please see a screenshot below.

    if “load_state” not in st.session_state:
    st.session_state.load_state = False

    with st.form(‘input’):
    text_input = st.text_area(“Enter text here”, height=350)
    submit_button = st.form_submit_button(label=“Extract data”)

    if submit_button or st.session_state.load_state:
    st.session_state.load_state = True
    df = pd.DataFrame(data = {‘column1’: [‘a’, ‘b’, ‘c’], ‘column2’: [1,2,3]})
    AgGrid(df, reload_data = False)

    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.

    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.

    Reject all Accept all