Dash AG and Big Data

Hi,

AgGrid looks like a great alternative to dash-tabulator (better dash support).

I have some data : over 900.000 rows and 21 columns.

What is the best way to have a seamless experience?
In ‘pagination’ mode (user defined page size) as well as in ‘unlimited scroll’ mode.

hi @popo
Did you get a chance to review the section of the docs on pagination?

Hello @popo,

I think it is possible to use pagination along with rowModelType="infinite", this way you are only querying a single page from the server at a time.

Here, check this out:

import dash_ag_grid as dag
import dash
from dash import Input, Output, html, dcc, no_update
import pandas as pd

app = dash.Dash(__name__)


df = pd.read_csv(
    "https://raw.githubusercontent.com/plotly/datasets/master/liquor_iowa_2021.csv"
)


app.layout = html.Div(
    [
        dcc.RadioItems(
            id="columnSizing",
            options=[
                {"label": i, "value": j}
                for i, j in [
                    ("Auto size", "autoSize"),
                    ("Size to fit", "sizeToFit"),
                ]
            ],
            value="autoSize",
        ),
        dag.AgGrid(
            id="grid",
            columnDefs=[{"field": i} for i in df.columns],
            rowModelType="infinite",
            columnSize="autoSize",
            defaultColDef=dict(
                resizable=True,
                sortable=True,
                filter=True,
                minWidth=100
            ),
            dashGridOptions={"pagination":True}
        ),
    ]
)


@app.callback(Output("grid", "columnSize"), Input("columnSizing", "value"))
def column_sizing(size_type):
    return size_type

@app.callback(
    Output("grid", "getRowsResponse"),
    Input("grid", "getRowsRequest"),
)
def infinite_scroll(request):
    if request is None:
        return no_update
    partial = df.iloc[request["startRow"] : request["endRow"]]
    return {"rowData": partial.to_dict("records"), "rowCount": len(df.index)}


if __name__ == "__main__":
    app.run_server(debug=True)

If you use infinite model, you need to also use server side filtering and sorting.

4 Likes

Great @jinnyzor !

just Great !!

But…
I had to upgrade to dash-ag-grid==2.0.0rc2 to run the above code.
(as stipulated at the time of this post on dashaggrid.pythonanywhere.com in the Getting Started section)
I run into a problem running the ’ Filtering and Sorting’ code.

Several arguments are unknown (commented below).

dag.AgGrid(
    id="grid1",
    rowModelType="infinite",
    #rowSelection="multiple",
    columnSize="sizeToFit",
    columnDefs=columnDefs,
    defaultColDef={"sortable": True, 'filter': True},
    ## The number of rows rendered outside the viewable area the grid renders.
    # rowBuffer=0,
    ## How many blocks to keep in the store. Default is no limit, so every requested block is kept.
    # maxBlocksInCache=1,
    # multiSortKey=True
),

rowSelection, rowBuffer, maxBlocksInCache, multiSortKey

when i run the ’ Filtering and Sorting’ code :

Am I doing something wrong?

1 Like

As far as the commented out areas, you’ll need to toss those into dashGridOptions.

What is the full code of the things that you are running? Also, as far as the code to use, use the second post on that issue. In the first I was sorting some things out.