DataTables v2 for Shiny for Python — anywidget binding, Python port of the R DT2 package
Project description
dt2 — DataTables v2 for Shiny for Python
A Python port of the R DT2 package: an anywidget binding for DataTables v2, designed for Shiny for Python (and usable in Jupyter).
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.
Status: feature-complete toward R parity, pre-release. Config, all 15 extensions, server-side processing, proxy, events and inline inputs are implemented and unit-tested. The live in-browser Comm transport has not yet been visually verified. See ROADMAP.md and CHANGELOG.md.
Install (dev)
npm install && npm run build # build the JS bundle into src/dt2/static/
uv venv && uv pip install -e ".[shiny,pandas]"
(The built bundle is committed, so an installed wheel needs no Node toolchain.)
Quick start
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)
Configure with Options
Chainable builder mirroring the R pipe helpers:
from dt2 import Options, JS, dt2
opts = (Options(df)
.cols_align(["revenue"], "right")
.format_number(["revenue"], thousands=".", decimal=",", digits=2, prefix="R$ ")
.format_datetime(["updated"], from_="YYYY-MM-DD", to="DD/MM/YYYY")
.cols_render(["score"], JS("function(d,t){ return t==='display' ? d+'%' : d; }"))
.order(("revenue", "desc"))
.length_menu([10, 25, -1]))
dt2(df, options=opts)
JS(...) is the parity for htmlwidgets::JS(): the source is revived into a
real function in the browser, with DataTable, $ and moment in scope.
Extensions
All 15 DataTables extensions are bundled; activate via Options:
opts = (Options(df)
.buttons(["copyHtml5", "csvHtml5", "excelHtml5"]) # jszip bundled; PDF needs pdfmake
.select({"style": "os"})
.responsive()
.fixed_header()
.row_group("field"))
dt2.extensions() lists what is bundled.
Server-side processing
Keep large data Python-side; DataTables fetches pages over the Comm:
dt2(big_df, server_side=True, pageLength=25)
Filtering/ordering/paging run in dt2.server.process_ssp.
Proxy, events and inline inputs
# proxy (Python -> table): call on the rendered widget
tbl.widget.search("ada")
tbl.widget.order(("field", "desc"))
tbl.widget.select_rows([1, 3])
# events (table -> Python): read reactively
from shinywidgets import reactive_read
reactive_read(tbl.widget, "selected_rows") # also: state, row_check, row_button
# inline row inputs
opts = Options(df).col_checkbox("select", value_col="active").col_button("act", label="Ping")
See examples/ for runnable apps:
app.py, app_config.py, app_extensions.py, app_serverside.py,
app_proxy_inputs.py.
How it relates to the R package
The DataTables runtime is shared conceptually with R DT2. What differs 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 +
client-side reviver. See the header of js/index.js for the full mapping.
License
MIT © André Leite
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dt2-0.1.0.tar.gz.
File metadata
- Download URL: dt2-0.1.0.tar.gz
- Upload date:
- Size: 266.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a49164a4a37ab8f30ef828b7b70a025fb84d478d04cc059fae101bca3c014908
|
|
| MD5 |
66270d3a93c9dd946331bd0ec814aab7
|
|
| BLAKE2b-256 |
e1e088e9d0a699093eccc80afc9d2b02da4c6287c15c038dbeab3236957f9ed8
|
Provenance
The following attestation bundles were made for dt2-0.1.0.tar.gz:
Publisher:
release.yml on StrategicProjects/dt2py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dt2-0.1.0.tar.gz -
Subject digest:
a49164a4a37ab8f30ef828b7b70a025fb84d478d04cc059fae101bca3c014908 - Sigstore transparency entry: 1970765849
- Sigstore integration time:
-
Permalink:
StrategicProjects/dt2py@1a716a436a59340bd6599fc1eb8b5da8b02a9af5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/StrategicProjects
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1a716a436a59340bd6599fc1eb8b5da8b02a9af5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dt2-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dt2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 246.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
620696a03aea522b87207f53f5db0b8eab6ae42b4dd5e27188bd4616d91037a9
|
|
| MD5 |
6ec831927cd3aa6f9b1756365f9aef19
|
|
| BLAKE2b-256 |
d3b255c013f826a10042124a6985942536cf8a4594fca39ad04fd53c244b1fb4
|
Provenance
The following attestation bundles were made for dt2-0.1.0-py3-none-any.whl:
Publisher:
release.yml on StrategicProjects/dt2py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dt2-0.1.0-py3-none-any.whl -
Subject digest:
620696a03aea522b87207f53f5db0b8eab6ae42b4dd5e27188bd4616d91037a9 - Sigstore transparency entry: 1970765959
- Sigstore integration time:
-
Permalink:
StrategicProjects/dt2py@1a716a436a59340bd6599fc1eb8b5da8b02a9af5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/StrategicProjects
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1a716a436a59340bd6599fc1eb8b5da8b02a9af5 -
Trigger Event:
release
-
Statement type: