Py.Cafe

huong-li-nguyen/

ag-grid-cell-shading

AG Grid with Cell Shading and Random Data

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# check out https://dash.plotly.com/ for documentation
# And check out https://py.cafe/maartenbreddels for more examples
mport dash_ag_grid as dag
from dash import Dash, html
import pandas as pd
import numpy as np


df = pd.DataFrame(np.random.randint(-100, 100, size=(10, 6)), columns=list("abcdef"))
df["items"] = [f"Item {i}" for i in range(len(df))]
df_numeric_columns = df.select_dtypes("number")
min = df_numeric_columns.min().min()
max = df_numeric_columns.max().max()

columnDefs = [{"field": "items"}] + [
    {
        "field": field,
        "cellStyle": {"function": "heatMap(params)"},
        "cellRendererParams": {"min": min, "max": max},
    }
    for field in df.columns[:-1]
]

app = Dash()

app.layout = html.Div(
    [
        dag.AgGrid(
            id="styling-cells-shading-3",
            columnDefs=columnDefs,
            rowData=df.to_dict("records"),
            columnSize="responsiveSizeToFit",
            dashGridOptions={"suppressRowHoverHighlight": True, "animateRows": False},
        )
    ]
)

app.run(debug=True)