Skip to content

Repository files navigation

ipyregulartable

An AnyWidget wrapper around spaday-regular-table for Jupyter.

Build Status codecov License PyPI FINOS Incubating Binder

Installation

Install the Python package. AnyWidget supplies the Jupyter integration, so there is no labextension or nbextension to install.

pip install ipyregulartable

Conda packages are available from conda-forge:

conda install -c conda-forge ipyregulartable

Usage

Pass a NumPy array, pandas Series, pandas DataFrame, or DataModel to RegularTableWidget:

import pandas as pd

from ipyregulartable import RegularTableWidget

table = RegularTableWidget(
    pd.DataFrame(
        {
            "symbol": ["AAPL", "MSFT"],
            "price": [201.5, 418.0],
        }
    )
)
table

The widget is a spaday.Widget. It renders the spaday-regular-table custom element and uses Spaday's component tree and action runtime for browser behavior.

Register a click callback with the existing API:

table.on_click(lambda widget, coordinates: print(coordinates))

Set table height and static CSS rules from Python:

table.height = 400
table.css = {
    "theadth": "background: #f2f4f7; font-weight: 700",
    "td": "padding-inline: 0.75rem",
}

Data models

Custom data models implement the abstract methods on DataModel:

from abc import abstractmethod

from ipyregulartable import DataModel


class MyDataModel(DataModel):
    @abstractmethod
    def editable(self, x, y):
        """Return whether the cell at (x, y) is editable."""

    @abstractmethod
    def rows(self):
        """Return the total number of rows."""

    @abstractmethod
    def columns(self):
        """Return the total number of columns."""

    @abstractmethod
    def dataslice(self, x0, y0, x1, y1):
        """Return a data slice, inclusive of both coordinate pairs."""

spaday-regular-table keeps row records in the browser and virtualizes their DOM rendering. This implementation materializes at most 1,000,000 cells when the widget is created or redrawn. Larger models raise ValueError instead of sending an unbounded payload over the widget comm.

Compatibility

The Spaday implementation supports:

  • NumPy arrays, pandas Series, pandas DataFrames, and bounded custom DataModel objects;
  • viewport-virtualized rendering through spaday-regular-table;
  • on_click, draw, setData, dataslice, and editable;
  • height, virtual_mode, and static css rules.

The following legacy features need a Python data-provider protocol in spaday-regular-table and are not implemented:

  • Python-backed viewport slices such as TwoBillionRows;
  • in-cell editing and on_edit callbacks;
  • expression-based styler rules.

License

Licensed under the Apache License 2.0. See LICENSE, NOTICE, and AUTHORS.

Note

This library was generated using Copier from the Base Python Project Template.

Releases

Used by

Contributors

Languages