dt2¶
DataTables v2 for Shiny for Python — an anywidget binding for DataTables v2, and the Python port of the R DT2 package.
It configures DataTables via plain Python (1:1 with the JS API), reusing the same DataTables runtime (2.3.4) and extensions as the R package. Works in Shiny for Python and Jupyter.
import pandas as pd
from shiny import App, ui
from shinywidgets import output_widget, render_widget
from dt2 import dt2
df = pd.read_csv("data.csv")
app_ui = ui.page_fluid(output_widget("tbl"))
def server(input, output, session):
@render_widget
def tbl():
return dt2(df, select=True, pageLength=10)
app = App(app_ui, server)
What you get¶
- Configurable tables via a chainable
Optionsbuilder (formats, alignment, ordering, custom JS renderers). - All 15 DataTables extensions bundled (Buttons, Select, Responsive, FixedHeader, SearchPanes, RowGroup, …).
- Server-side processing for large data, over the widget Comm.
- Proxy, events and inline inputs wired to Shiny reactivity.
Relationship to the R package¶
dt2 mirrors the API of the R DT2
package. The difference is the transport: R talks to Shiny via window.Shiny;
here the widget talks to the Python kernel over the anywidget Comm, bridged to
Shiny reactivity by shinywidgets. The htmlwidgets::JS() mechanism becomes the
JS() marker plus a client-side reviver.
| R | Python | |
|---|---|---|
| Package | DT2 (CRAN) |
dt2 (PyPI) |
| Frontend | htmlwidgets / Shiny (R) | anywidget / Shiny for Python |
| Docs | pkgdown site | this site |