To upload files, please first save the app
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid
from code_editor import code_editor
import json
# Load sample dataset
df = pd.read_json("https://www.ag-grid.com/example-assets/olympic-winners.json")
groupby = st.checkbox("Group by country and age", False)
gridOptions = {
'rowSelection': "multiple",
'groupSelectsChildren': True,
'autoGroupColumnDef': {
'headerName': 'My Group',
'minWidth': 220,
'cellRendererParams': {
'suppressCount': False,
'checkbox': True,
}
},
'columnDefs': [
{ 'field': "athlete", 'minWidth': 150,},
# First group by by country
{ 'field': "country", 'minWidth': 150, 'rowGroup': groupby, 'hide': groupby},
# Second group by by age
{ 'field': "age", 'maxWidth': 90, 'rowGroup': groupby, 'hide': groupby},
{ 'field': "year", 'maxWidth': 90 },
{ 'field': "date", 'minWidth': 150 },
{ 'field': "sport", 'minWidth': 150 },
{ 'field': "gold" },
{ 'field': "silver" },
{ 'field': "bronze" },
{ 'field': "total" },
],
'defaultColDef': {
'flex': 1,
'minWidth': 100,
},
};
tabs = st.tabs(['Grid', 'GridOptions', 'AgGridReturn.selected_data'])
with tabs[0]:
response = AgGrid(df, gridOptions, key='grid1')
with tabs[1]:
text = code_editor(
json.dumps(gridOptions, indent=4),
lang="json",
props={'readOnly': False},
height='300px'
).get('text', '')
if text != '':
gridOptions = json.loads(text)
with tabs[2]:
selected_data = response.selected_data
if selected_data is None:
st.write('Nothing was selected!')
else:
st.write(response.selected_data)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?