Skip to content

Instantly share code, notes, and snippets.

@asehmi
Created April 19, 2022 15:19
Show Gist options
  • Save asehmi/a32b9d683a2f7fec9309f8ac6069f25c to your computer and use it in GitHub Desktop.
Save asehmi/a32b9d683a2f7fec9309f8ac6069f25c to your computer and use it in GitHub Desktop.
Streamlit AgGrid Demo
# https://discuss.streamlit.io/t/selection-is-sometimes-not-returned-from-custom-widgets/21202
import streamlit as st
# https://github.com/PablocFonseca/streamlit-aggrid
from st_aggrid import AgGrid, GridOptionsBuilder
import pandas as pd
import numpy as np
np.random.seed(42)
# @st.experimental_memo
def get_df():
df = pd.DataFrame(columns=['foo','bar','baz'], data=np.random.choice(range(10), size=(10,3)))
return df
df = get_df()
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_default_column(value=True, enableRowGroup=True, aggFunc=None, editable=True)
gb.configure_selection(selection_mode="multiple", use_checkbox=True)
def display_table():
grid_response = AgGrid(df, gridOptions=gb.build(),
height=700,
data_return_mode="AS_INPUT",
update_mode="SELECTION_CHANGED",
theme="streamlit",
# enable_enterprise_modules=True,
)# .style.apply(highlight_clusters, axis=1)
selected = grid_response['selected_rows']
st.write("Selected rows:")
st.write(selected)
if st.checkbox('Use a form', value=True):
with st.form("table_form", clear_on_submit=False):
display_table()
if st.form_submit_button("Submit"):
pass
else:
display_table()
@asehmi
Copy link
Author

asehmi commented Apr 19, 2022

aggrid-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment