How to create tables in plotly Dash (dbc.Table, DataTable, AG Grid comparison)

Hello everyone,

I’ve written a comprehensive guide on how to display tabular data in Dash.
I think it is not obvious to beginners to understand what are the options and what are the pros/cons.

Here is the article:

I hope it is clear, although I found it really hard to make it short & simple while outlining the differences between each solution, especially DataTable vs. AG Grid. It is meant to be an intro because the documentation remains the most effective way to really grasp the differences with all the available examples (IMO).

What do you think about it ?
What solution do you use and when ?

-Fran

7 Likes

One of the best guides I’ve read, comparing table components in the Dash ecosystem. Well done, @spriteware .

How did you get the tables to display directly inside the article?

Thanks @adam :pray:

The tables are small dash apps running on my server, embedded using iframes (eg: https://scripts.dash-resources.com/tables/app_dag1.py/)
I guess it is the simplest way, as I use Wordpress for the blog.

1 Like

The iframes and app content work really well, such a great way to display the differences in the tables on a web page. Are you running the apps from a web hosting server or by “my server” do you have a dedicated server you are able to deploy the apps from? I’m interested in being able to display snippets of an app in this way; do you think would that work with heroku, pycafe, and other python deployment sites? I’ll have to explore!

Looking forward to seeing more content on your website! Nice work!

2 Likes

Thank you for the thoughtful comparison! It’s always great to see such a detailed overview.

That said, I’m a bit concerned that based on the article some people might not try Dash AG Grid because they think it’s too complex or requires JavaScript. I know your article wasn’t focused solely on Dash AG Grid, so I wanted to take a moment to highlight some of its beginner-friendly features.

While Dash AG Grid offers a wide range of advanced features, it doesn’t require JavaScript unless you’re working with more advanced customizations.

What makes Dash AG Grid so powerful is that many of its features come pre-configured by default, allowing users to get started quickly with very little setup. This makes it a great choice not only for advanced users but also for those new to Dash or data grids.

Using the dataset from the blog, here is an example:


from dash import Dash, html
import dash_ag_grid as dag
import pandas as pd

app = Dash(__name__)

url = "https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv"
df = pd.read_csv(url)
df["Survived"] = df["Survived"].astype(bool)

app.layout = html.Div([
    dag.AgGrid(
        rowData=df.to_dict('records'),
        columnDefs=[{"field": i} for i in df.columns],
        defaultColDef={"filter":True, "editable":True},
    )
])

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


This simple app, which takes only five lines of code to configure the grid, already enables all these features:

Basic grid features enabled by default:

  • Alpine Theme Styling: The grid comes styled with the Alpine theme, available in both light and dark modes. To see the grid in a dark theme add className="ag-theme-alpine-dark"

  • Column Resizing: Resize columns by dragging the vertical handle in the header.

  • Sorting Rows: Click on the header to sort rows; use shift-click for sorting by multiple columns.

  • Animation: See the smooth row animation during sorting and filtering.

  • Boolean Values as Checkboxes: Boolean values are automatically rendered as checkboxes.

  • Column Reordering: Change the order of the columns by dragging the column header.

  • Column Pinning: Pin a column to the right or left side of the grid by dragging the column header.

Sorting and filter, editing defaults:

Based on the data type of the column, the following features are automatically configured:

  • The Text columns : Uses a text editor and the values are sorted and filtered as strings.

  • The Number columns : Uses a number editor and number filter.

  • The Boolean columns: The value renders as a checkbox and it uses a checkbox filter.

  • The dateString columns: If there was a date column in this dataset, you would see that the date editor, date filter and sort works automatically if the date is in the format yyyy-mm-dd.

Note how the filter is menu-driven and it changes based on the column type.
ag-grid-intro

Built-in Components (no JavaScript Required)

Dash AG Grid comes with a library of built-in components, eliminating the need for custom components in most cases. For instance:

Cell Editors cell editors

  • Text Cell Editor: The default editor, is a standard HTML input component

  • Large Text Cell Editor: is an HTML textarea component

  • Select Cell Editor: is an HTML select component

  • Rich Select Cell Editor (Enterprise only): A custom dropdown component

  • Number Cell Editor*: is an HTML number input

  • Date Cell Editor*: is an HTML date input

  • Checkbox Cell Editor*: is an HTML checkbox input

Other Components:

  • Markdown Component Use markdown syntax in cells

  • Show changes Cell Renderer - provides annimation when cell values change

  • Tooltips Configure basic tooltips to show in cells and headers

  • Buttons: There is not built-in button, but any cell can act as a button by using the n_clicks prop in a callback. If you don’t want to create a custom button, you can simply style the cell with CSS to look like a button.

For those of you who have not tried Dash AG Grid yet, I recommend starting with something simple—like exploring a dataframe using the sample app. Then check out the docs to add more features. Give Dash AG Grid a try—you’ll be amazed at what it can do!

@spriteware Your blog posts are fantastic! I agree that the Dash AG Grid docs are detailed and thorough, which is great for reference but can feel a bit overwhelming for someone new to the grid. More step-by-step tutorials, like the ones you’ve created, would really help new users get started. If you’re thinking about making more on Dash AG Grid, I’d be happy to help, if you like!

3 Likes

Hi @AnnMarieW !

Thank your for your answer! As the O.G. of datatable, AG Grid, DBC… and basically everything else in Dash, I was waiting for your comment :smiley:

I’m happy that you took the time to detail more about Dash AG Grid here. This is why I created this post, to gather different opinions.

I plan to do a few tutorials on datatable and AG Grid, and especially on AG Grid. Precise articles like “how to style AG Grid”, “how to add a button”, “how to add interactaction between a table and chart”, …
If you have ideas of topics to be covered precisely (recurrent errors or questions), this is something that could help me.

@spriteware I’m delighted that you are planning more articles on AG Grid. I’ll send you a PM and we can chat about some ideas.