Dash DataTable

Dash DataTable (dash.dash_table.DataTable) is an interactive table component designed for viewing, editing, and exploring large datasets.

This component was written from scratch in React.js specifically for the Dash community. Its API was designed to be ergonomic and its behavior is completely customizable through its properties. DataTable is rendered with standard, semantic HTML <table/> markup, which makes it accessible, responsive, and easy to style.

Import DataTable with:

from dash import dash_table

Quickstart

Dash open-source
Dash Enterprise Design Kit
using Dash
using CSV, DataFrames   

df = CSV.read(download("https://raw.githubusercontent.com/plotly/datasets/master/solar.csv"), DataFrame)

app = dash()

app.layout = dash_datatable(
    id="table",
    columns=[Dict("name" =>i, "id" => i) for i in names(df)],
    data = Dict.(pairs.(eachrow(df)))
)

run_server(app, "0.0.0.0", debug=true)
State
Number of Solar Plants
Installed Capacity (MW)
Average MW Per Plant
Generation (GWh)
California
289
4395
15.3
10826
Arizona
48
1078
22.5
2550
Nevada
11
238
21.6
557
New Mexico
33
261
7.9
590
Colorado
20
118
5.9
235
Texas
12
187
15.6
354
North Carolina
148
669
4.5
1162
New York
13
53
4.1
84

The data and columns properties are the first two arguments of dash_table_datatable. You can set these with positional or keyword arguments. The following examples define the same DataTable:

dash_table.DataTable(
    df.to_dict('records'),
    [{"name": i, "id": i} for i in df.columns]
)
dash_table.DataTable(
    data=df.to_dict('records'),
    columns=[{"name": i, "id": i} for i in df.columns]
)

You can also omit columns. When no columns argument is provided, columns are auto-generated based on the first row in data.

dash_table.DataTable(df.to_dict('records'))

Table with Click Callback

replit      colab      databricks

using Dash, DashBootstrapComponents
using CSV, DataFrames   

app = dash()

df = CSV.read(download("https://git.io/Juf1t"), DataFrame)

app = dash(external_stylesheets=[dbc_themes.BOOTSTRAP])

app.layout = dbc_container([
    dbc_label("Click a cell in the table:"),
    dash_datatable(
        id="tbl", 
        columns=[Dict("name" =>i, "id" => i) for i in names(df)],
        data = Dict.(pairs.(eachrow(df)))
    ),
    dbc_alert("Click the table", id="tbl_out"),
])

callback!(app,
    Output("tbl_out", "children"), 
    Input("tbl", "active_cell")
) do active_cell
  return string(active_cell)
end

run_server(app, "0.0.0.0", debug=true)
State
Number of Solar Plants
Installed Capacity (MW)
Average MW Per Plant
Generation (GWh)
California
289
4395
15.3
10826
Arizona
48
1078
22.5
2550
Nevada
11
238
21.6
557
New Mexico
33
261
7.9
590
Colorado
20
118
5.9
235
Texas
12
187
15.6
354
North Carolina
148
669
4.5
1162
New York
13
53
4.1
84

Sign up for Dash Club → Two free cheat sheets plus updates from Chris Parmer and Adam Schroeder delivered to your inbox every two months. Includes tips and tricks, community apps, and deep dives into the Dash architecture. Join now.

User Guide

Reference

A comprehensive list of all of the DataTable properties.

DataTable Height

How to set the height of the DataTable. Examples include how to set the height with vertical scroll, pagination, virtualization, and fixed headers.

DataTable Width & Column Width

How to set the width of the table and the columns. Examples include how to handle word wrapping, cell clipping, horizontal scroll, fixed columns, and more.

Styling

The style of the DataTable is highly customizable. This chapter includes examples for:

  • Displaying multiple rows of headers
  • Text alignment
  • Styling the table as a list view
  • Changing the colors (including a dark theme!)
Conditional Formatting

Several examples of how to highlight certain cells, rows, or columns based on their value or state.

Number Formatting

Several examples of how to format and localize numbers.

Sorting, Filtering, Selecting, and Paging Natively

The DataTable is interactive. This chapter demonstrates the interactive features of the table and how to wire up these interations to Python callbacks. These actions include:

  • Paging
  • Selecting Rows
  • Sorting Columns
  • Filtering Data
DataTable Tooltips

Display tooltips on data and header rows, conditional tooltips, define tooltips for each cell, customize behavior.

Python-Driven Filtering, Paging, Sorting

In Part 3, the paging, sorting, and filtering was done entirely clientside (in the browser). This means that you need to load all of the data into the table up-front. If your data is large, then this can be prohibitively slow. In this chapter, you'll learn how to write your own filtering, sorting, and paging backends in Python with Dash. We'll do the data processing with Pandas but you could write your own routines with SQL or even generate the data on the fly!

Editable DataTable

The DataTable is editable. Like a spreadsheet, it can be used as an input for controlling models with a variable number of inputs. This chapter includes recipes for:

  • Determining which cell has changed
  • Filtering out null values
  • Adding or removing columns
  • Adding or removing rows
  • Ensuring that a minimum set of rows are visible
  • Running Python computations on certain columns or cells
Typing and User Input Processing

In this chapter, you'll learn how to configure the table to

  • assign the column type
  • change the data presentation
  • change the data formatting
  • validate or coerce user data input
  • apply default behavior for valid and invalid data
Dropdowns Inside DataTable

Cells can be rendered as editable Dropdowns. This is our first stake in bringing a full typing system to the table. Rendering cells as dropdowns introduces some complexity in the markup and so there are a few limitations that you should be aware of.

Virtualization

Examples using DataTable virtualization.

Filtering Syntax

An explanation and examples of filtering syntax for both frontend and backend filtering in the DataTable.