basic
To upload files, please first save the app
import streamlit as st
from st_aggrid import AgGrid, GridOptionsBuilder
import pandas as pd
import numpy as np
# Set page config
try:
st.set_page_config(layout='wide')
except:
pass
st.title("Basic AgGrid Example")
# Create sample data
@st.cache_data
def get_sample_data():
np.random.seed(42)
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve', 'Frank'],
'Age': [25, 30, 35, 28, 32, 29],
'Salary': [50000, 60000, 70000, 55000, 65000, 58000],
'Department': ['Engineering', 'Marketing', 'Engineering', 'HR', 'Marketing', 'Engineering'],
'Hired Date': pd.date_range('2020-01-01', periods=6, freq='3M').date
}
return pd.DataFrame(data)
df = get_sample_data()
st.markdown("## Simple AgGrid Display")
st.markdown("This is a basic example of displaying a DataFrame with AgGrid.")
# Basic AgGrid without configuration
st.subheader("Basic Grid (No Configuration)")
AgGrid(df, key='basic_grid')
# Grid with basic configuration
st.subheader("Grid with Configuration")
# Build grid options
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_pagination(paginationAutoPageSize=True)
gb.configure_selection('single')
gb.configure_side_bar()
gridOptions = gb.build()
grid_response = AgGrid(
df,
gridOptions=gridOptions,
height=400,
width='100%',
data_return_mode='AS_INPUT',
update_mode='MODEL_CHANGED',
fit_columns_on_grid_load=True,
key='configured_grid'
)
# Display selected data
if grid_response['selected_rows']:
st.subheader("Selected Row Data:")
selected_df = pd.DataFrame(grid_response['selected_rows'])
st.table(selected_df)
st.markdown("## Features Demonstrated")
st.markdown("""
- Basic data display
- Row selection
- Pagination
- Sidebar with filters
- Fit columns to container
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?