PablocFonseca / streamlit-aggrid

Implementation of Ag-Grid component for Streamlit
https://pypi.org/project/streamlit-aggrid/
MIT License
1.06k stars 202 forks source link

Display cannot be set to false #51

Closed enviromachinebeast closed 6 months ago

enviromachinebeast commented 2 years ago

Once a strealit aggrid component is displayed, and in case another aggrid needs to be displayed and the earlier one needs to be undiplayed it does not happen. I tried it with st.experimental_reload() or displaying a second aggrid with different key.

MarkSimUM commented 2 years ago

Not sure if this is what you are looking to do, but I found you can reuse the same grid by putting it in a form.

with st.form(key='gridform'):
        submit_button = st.form_submit_button(label='Submit')
        if submit_button:
           # if button pushed, run the query 
            df = runQuery(queryText,False)
            print(df)
            gb = GridOptionsBuilder.from_dataframe(df)
            gb.configure_pagination()
            gb.configure_side_bar()
            gb.configure_default_column(groupable=True, value=True, enableRowGroup=True, aggFunc="sum", editable=False)
            gridOptions = gb.build()
            gridA = AgGrid(df, gridOptions=gridOptions, enable_enterprise_modules=True,reload_data=True, key= "grid1")

Likewise, you can specify 2 or more grids and determine which you want to display:

with st.form(key='gridform'):
        submit_button = st.form_submit_button(label='Submit')
        if submit_button:
           # if button pushed, run the query 
            df = runQuery(queryText,False)
            gb = GridOptionsBuilder.from_dataframe(df)
            gb.configure_pagination()
            gb.configure_side_bar()
            gb.configure_default_column(groupable=True, value=True, enableRowGroup=True, aggFunc="sum", editable=False)
            gridOptions = gb.build()
            if showgrid == 1:
                gridA = AgGrid(df, gridOptions=gridOptions, enable_enterprise_modules=True,reload_data=True, key= "grid1")
            if showgrid == 2:    
                gridB = AgGrid(df, gridOptions=gridOptions, enable_enterprise_modules=True,reload_data=True, key= "grid2")