CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-itables

Python library that transforms Pandas and Polars DataFrames into interactive DataTables with sorting, pagination, and filtering capabilities.

Pending
Overview
Eval results
Files

framework-extensions.mddocs/

Framework Extensions

Specialized components and functions for integrating interactive tables into various Python application frameworks. Each extension provides framework-specific functionality while maintaining the core ITables API and configuration system.

Capabilities

Streamlit Integration

Interactive table component for Streamlit applications, providing seamless integration with Streamlit's component system and reactivity model.

def interactive_table(df, key=None, caption=None, **kwargs):
    """
    Render DataFrame as interactive datatable in Streamlit applications.

    Parameters:
    - df: Pandas/Polars DataFrame or Series to display
    - key (str, optional): Unique key for Streamlit component (for caching/reactivity)
    - caption (str, optional): Table caption text
    - **kwargs: ITableOptions - Configuration options

    Returns:
    CustomComponent: Streamlit component instance
    """

Shiny Integration

Functions for rendering interactive tables in Shiny for Python applications, with support for row selection events and reactive programming patterns.

def init_itables(connected=False, dt_bundle=None):
    """
    Initialize DataTables library for Shiny applications.

    Parameters:
    - connected (bool): If True, load from CDN; if False, use offline bundle
    - dt_bundle (str | Path, optional): Custom DataTables bundle path

    Returns:
    str: HTML content to include in Shiny app header
    """

def DT(df, caption=None, **kwargs):
    """
    Render DataFrame as interactive table in Shiny applications with row selection.

    Parameters:
    - df: Pandas/Polars DataFrame or Series to display
    - caption (str, optional): Table caption text
    - **kwargs: ITableOptions - Configuration options

    Returns:
    str: HTML representation with Shiny integration

    Note: If table_id is provided, selected rows are available as Shiny input
    """

Dash Integration

Dash component class for creating interactive tables in Dash applications, with full integration into Dash's callback system and property updates.

class ITable:
    """
    Dash component for interactive tables.

    Properties:
    - id (str): Unique component identifier (required)
    - All ITableOptions as component properties
    - selected_rows (list): Currently selected row indices (output property)
    """

    def __init__(self, id, df=None, caption=None, **kwargs):
        """
        Initialize ITable Dash component.

        Parameters:
        - id (str): Unique component ID (required, must be non-empty string)
        - df: Pandas/Polars DataFrame or Series to display
        - caption (str, optional): Table caption text
        - **kwargs: ITableOptions - Configuration options

        Raises:
        ValueError: If id is not a non-empty string
        """

# Additional Dash utilities
ITABLE_PROPERTIES: dict  # Component property definitions
ITableOutputs: type  # Output property types for callbacks
def updated_itable_outputs(*args): # Helper for handling updated outputs

Jupyter Widget Integration

AnyWidget-based interactive table widget for Jupyter environments, providing reactive properties and bi-directional communication between Python and JavaScript.

class ITable:
    """
    AnyWidget-based interactive table widget.

    Traits (automatically synced with frontend):
    - caption (str): Table caption
    - classes (str): CSS classes  
    - selected_rows (list[int]): Selected row indices
    - style (str): CSS styles (private, use style property)
    """

    def __init__(self, df=None, caption=None, **kwargs):
        """
        Initialize ITable widget.

        Parameters:
        - df: Pandas/Polars DataFrame or Series to display
        - caption (str, optional): Table caption text
        - **kwargs: ITableOptions - Configuration options
        """

    def update(self, df=None, caption=None, **kwargs):
        """
        Update table data, attributes, or DataTable arguments.

        Parameters:
        - df: New DataFrame/Series (None = keep current)
        - caption (str, optional): New caption (None = keep current)
        - **kwargs: Updated configuration options (None values remove options)

        Returns:
        None (updates widget in-place)
        """

    @property
    def df(self):
        """Get current DataFrame."""

    @df.setter
    def df(self, df):
        """Set new DataFrame (triggers update)."""

    @property  
    def style(self):
        """Get current CSS styles."""

    @style.setter
    def style(self, style):
        """Set CSS styles."""

Usage Examples

Streamlit Application

import streamlit as st
import pandas as pd
from itables.streamlit import interactive_table

# Create sample data
df = pd.DataFrame({
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Score': [95, 87, 92],
    'Grade': ['A', 'B', 'A']
})

# Display in Streamlit
st.title("Student Scores")
interactive_table(df, 
                 key="student_table",
                 caption="Class Scores",
                 pageLength=10,
                 column_filters="header")

# Use with Streamlit columns
col1, col2 = st.columns(2)
with col1:
    interactive_table(df.head(2), key="table1")
with col2:
    interactive_table(df.tail(2), key="table2")

Shiny Application

from shiny import App, ui, render
import pandas as pd
from itables.shiny import DT, init_itables

# Sample data
df = pd.DataFrame({
    'Product': ['A', 'B', 'C', 'D'],
    'Sales': [100, 250, 300, 150]
})

app_ui = ui.page_fluid(
    ui.HTML(init_itables(connected=False)),  # Initialize ITables
    ui.h2("Sales Dashboard"),
    ui.output_ui("table"),
    ui.output_text("selection")
)

def server(input, output, session):
    @output
    @render.ui
    def table():
        return ui.HTML(DT(df, 
                         table_id="sales_table",
                         pageLength=5,
                         select=True))
    
    @output  
    @render.text
    def selection():
        selected = input.sales_table_selected_rows()
        if selected:
            return f"Selected rows: {selected}"
        return "No rows selected"

app = App(app_ui, server)

Dash Application

import dash
from dash import html, dcc, callback, Input, Output
import pandas as pd
from itables.dash import ITable

# Sample data
df = pd.DataFrame({
    'City': ['New York', 'London', 'Tokyo', 'Paris'],
    'Population': [8.4, 8.9, 13.9, 2.1],
    'Country': ['USA', 'UK', 'Japan', 'France']
})

app = dash.Dash(__name__)

app.layout = html.Div([
    html.H1("City Population Data"),
    ITable(
        id="city-table",
        df=df,
        caption="World Cities",
        pageLength=10,
        column_filters="header",
        select={'style': 'multi'}
    ),
    html.Div(id="selection-output")
])

@callback(
    Output("selection-output", "children"),
    Input("city-table", "selected_rows")
)
def update_selection(selected_rows):
    if selected_rows:
        selected_cities = df.iloc[selected_rows]['City'].tolist()
        return f"Selected cities: {', '.join(selected_cities)}"
    return "No cities selected"

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

Jupyter Widget

import pandas as pd
from itables.widget import ITable

# Create widget with initial data
df = pd.DataFrame({
    'Item': ['Widget A', 'Widget B', 'Widget C'],
    'Price': [10.50, 15.25, 8.75],
    'Stock': [100, 50, 200]
})

# Create interactive widget
table_widget = ITable(df, 
                     caption="Inventory",
                     pageLength=5,
                     column_filters="header")

# Display widget
table_widget

# Update data dynamically
new_df = pd.DataFrame({
    'Item': ['Widget D', 'Widget E'],
    'Price': [12.00, 9.50],
    'Stock': [75, 150]
})

table_widget.update(df=new_df, caption="Updated Inventory")

# Access selected rows
print(f"Selected rows: {table_widget.selected_rows}")

# Modify styling
table_widget.style = "background-color: #f0f0f0; border: 1px solid #ccc;"
table_widget.classes = "display compact hover"

Widget Event Handling

from ipywidgets import Output
import pandas as pd
from itables.widget import ITable

# Create output widget for logging
output = Output()
display(output)

# Create table widget
df = pd.DataFrame({'A': [1, 2, 3], 'B': ['x', 'y', 'z']})
table = ITable(df, select={'style': 'multi'})

# Monitor selection changes
def on_selection_change(change):
    with output:
        print(f"Selection changed: {change['new']}")

table.observe(on_selection_change, names='selected_rows')
table

Framework-Specific Features

Streamlit Features

  • Automatic integration with Streamlit's component system
  • Unique key parameter for proper caching and reactivity
  • Compatible with Streamlit's column layouts and containers

Shiny Features

  • Row selection events accessible as Shiny inputs
  • Integration with Shiny's reactive programming model
  • Support for both connected and offline DataTables modes
  • Automatic input value updates via JavaScript integration

Dash Features

  • Full Dash component with standard property system
  • Integration with Dash callbacks for reactivity
  • Selected rows available as output property
  • Support for all standard Dash component patterns

Jupyter Widget Features

  • Bi-directional data synchronization
  • Reactive properties using traitlets
  • Widget composition and event handling
  • Integration with ipywidgets ecosystem

Install with Tessl CLI

npx tessl i tessl/pypi-itables

docs

configuration.md

core-display.md

data-utilities.md

framework-extensions.md

index.md

type-system.md

tile.json