Drop files here
or click to upload
from st_aggrid import AgGrid, GridOptionsBuilder, JsCode
import pandas as pd
# Sample data
df = pd.DataFrame({
"product": ["Laptop", "Phone", "Tablet"],
"stock": [45, 8, 15],
"status": ["In Stock", "Low", "Low"]
})
# Custom cell styling based on stock levels
cellStyle = JsCode("""
function(params) {
if (params.column.colId === 'stock') {
if (params.value <= 10) {
return {
'backgroundColor': '#ffebee',
'color': '#c62828',
'fontWeight': 'bold'
};
} else if (params.value <= 20) {
return {
'backgroundColor': '#fff3e0',
'color': '#ef6c00'
};
}
}
return null;
}
""")
# Configure grid options
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_column("stock", cellStyle=cellStyle)
gb.configure_column("status")
grid_options = gb.build()
grid_return = AgGrid(
df,
gridOptions=grid_options,
allow_unsafe_jscode=True
)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?