Dash AG Grid

repository·v35·Indexed 42 days ago

https://github.com/plotly/dash-ag-grid

A Dash component wrapper for the AG Grid JavaScript library, version 35.3.0, enabling high-performance interactive data grids in Dash applications. It supports both Community and Enterprise features, including column resizing, sorting, pagination, and advanced capabilities like grouping and pivoting with a valid license. The component provides the AgGrid entrypoint and access to the underlying AG Grid API via getApi and getApiAsync.

Tokens
1.3K
Snippets
6
Records
11
Agent score
54%

What's inside Dash AG Grid

  1. Understand AG Grid Community vs Enterprise features

    v35

    Dash AG Grid includes both the AG Grid Community and Enterprise versions.

    • Community Features: Includes core functionality like column interactions (resize, reorder, pin), pagination, sorting, row selection, cell editing, custom cell components, and CSV export.
    • Enterprise Features: Requires a valid AG Grid license key. Includes advanced capabilities like Grouping/Aggregation, Advanced Filtering, Server-Side Records Operations, Excel Export, Pivoting, and Sparklines.

    Note: While both versions are included in the component, Enterprise features will not function without a license.

  2. Quick Start with AgGrid

    v35

    To create a basic grid, import dash_ag_grid as dag. You need to provide rowData (a list of dictionaries representing your data) and columnDefs (a list of dictionaries defining the columns).

    By default, the component enables the Alpine theme, sorting, column resizing/reordering/pinning, boolean checkboxes, and row animation on sort.

    import dash_ag_grid as dag
    from dash import Dash
    import pandas as pd
    
    app = Dash()
    
    df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/space-mission-data.csv")
    
    app.layout = dag.AgGrid(
        rowData=df.to_dict("records"),
        columnDefs=[{"field": i} for i in df.columns],
    )
    
    app.run(debug=True)
  3. Run Dash AG Grid examples

    v35

    To run the examples located in the more_examples directory, follow these steps:

    1. Set up your development environment according to the project's contribution guidelines.
    2. Install the necessary dependencies using the provided requirements file:
      pip install -r requires-docs.txt
    3. Execute the specific application script you wish to run. For example, to run the stock portfolio demo:
      python more_examples/demo_stock_portfolio_dmc/app.py

    Note: These examples have been moved to the official Dash documentation. This repository's examples are maintained for historical reference only.

    pip install -r requires-docs.txt
    python more_examples/demo_stock_portfolio_dmc/app.py
  4. Verify Component API and Python integration

    v35
    When developing or reviewing components, ensure that all component props are functional when controlled from the Python backend. A reliable way to verify this is to create a test application in usage.py to confirm that backend-driven updates correctly reflect in the frontend component.
  5. Run integration tests for components

    v35

    The Dash ecosystem relies heavily on integration tests. To run the sample integration test provided in the boilerplate (which launches a sample Dash app in a browser), use the following command from the root directory:

    python -m tests.test_render
  6. Document components using React docstrings

    v35

    To ensure compatibility with Dash documentation tools, provide basic documentation for your components using react docstrings. At a minimum, your documentation should include:

    • A description of what the component does.
    • A description of its props.
    • An explanation of the features enabled by those props.

    Ensure you use the correct formatting so that the docstrings are properly recognized by the Dash ecosystem.

  7. Prepare for publishing: Final scan

    v35
    Before publishing a component, perform a final check of external resources. Ensure that all external resources used by your component are explicitly referenced in the MANIFEST.in file to ensure they are included in the package distribution.
  8. Use the AgGrid component

    v35

    The AgGrid component is the primary entrypoint for rendering an AG Grid instance within a Dash application. It is imported from the dash-ag-grid package.

    import { AgGrid } from 'dash-ag-grid';
    
    // Usage within a React/Dash context
    <AgGrid ... />
  9. Access the AG Grid API with getApi and getApiAsync

    v35

    To interact with the underlying AG Grid instance (e.g., to trigger manual refreshes, export data, or manipulate columns programmatically), use getApi or getApiAsync.

    • getApi: Synchronously retrieves the AG Grid API instance.
    • getApiAsync: Asynchronously retrieves the AG Grid API instance, which is useful when the component might not be fully initialized yet.
    import { getApi, getApiAsync } from 'dash-ag-grid';
    
    // Synchronous access
    const api = getApi();
    
    // Asynchronous access
    const api = await getApiAsync();