diff --git a/404.html b/404.html index b71bb65..69eba8d 100644 --- a/404.html +++ b/404.html @@ -212,7 +212,7 @@
  • - + Examples @@ -578,6 +578,27 @@ +
  • + + + + + Showcase + + + + +
  • + + + + + + + + + +
  • diff --git a/api/index.html b/api/index.html index 9da9771..7ff9536 100644 --- a/api/index.html +++ b/api/index.html @@ -219,7 +219,7 @@
  • - + Examples @@ -587,6 +587,27 @@ +
  • + + + + + Showcase + + + + +
  • + + + + + + + + + +
  • @@ -763,30 +784,6 @@ +
  • + +
  • + + + TableOptions + + +
  • @@ -1020,30 +1026,6 @@ + + +
  • + + + TableOptions + + +
  • @@ -1261,7 +1252,7 @@

    table_options - TableOptions + TableOptions
    @@ -1269,7 +1260,7 @@

    - TableOptions() + {} @@ -1277,69 +1268,57 @@

    Source code in pytabulator/shiny_bindings.py -
    class render_data_frame(Renderer[DataFrame]):
    -    """A decorator for a function that returns a `DataFrame`
    -
    -    Args:
    -        table_options (TableOptions): Table options.
    -    """
    -
    -    editor: bool
    +              
    74
    +75
    +76
    +77
    +78
    +79
    +80
    +81
    +82
    +83
    +84
    +85
    +86
    +87
    +88
    +89
    +90
    +91
    +92
    +93
    +94
    +95
    +96
    +97
    +98
    +99
    class render_data_frame(Renderer[DataFrame]):
    +    """A decorator for a function that returns a `DataFrame`
    +
    +    Args:
    +        table_options (TableOptions): Table options.
    +    """
    +
    +    def auto_output_ui(self) -> Tag:
    +        return output_tabulator(self.output_id)
     
    -    def auto_output_ui(self) -> Tag:
    -        return output_tabulator(self.output_id)
    -
    -    def __init__(
    -        self,
    -        _fn: ValueFn[DataFrame] = None,
    -        *,
    -        table_options: TableOptions | TabulatorOptions = TableOptions(),
    -    ) -> None:
    -        super().__init__(_fn)
    -        self.table_options = table_options
    -
    -    async def render(self) -> Jsonifiable:
    -        df = await self.fn()
    -        # return {"values": value.values.tolist(), "columns": value.columns.tolist()}
    -        # TODO: convert with js
    -        data = df_to_dict(df)
    -        data["options"] = (
    -            asdict(self.table_options)
    -            if isinstance(self.table_options, TabulatorOptions)
    -            else self.table_options.model_dump(by_alias=True)
    -        )
    -        return data
    +    def __init__(
    +        self,
    +        _fn: ValueFn[DataFrame] = None,
    +        *,
    +        table_options: TableOptions | dict = {},
    +    ) -> None:
    +        super().__init__(_fn)
    +        self.table_options = table_options
    +
    +    async def render(self) -> Jsonifiable:
    +        df = await self.fn()
    +        # return {"values": value.values.tolist(), "columns": value.columns.tolist()}
    +        # TODO: convert with js
    +        data = df_to_dict(df)
    +        data["options"] = jsonifiable_table_options(self.table_options)
    +        return data
     
    @@ -1384,25 +1363,25 @@

    Source code in pytabulator/shiny_bindings.py -
    50
    -51
    -52
    -53
    -54
    -55
    -56
    -57
    -58
    -59
    class render_tabulator(Renderer[Tabulator]):
    -    """A decorator for a function that returns a `Tabulator` table"""
    -
    -    def auto_output_ui(self) -> Tag:
    -        return output_tabulator(self.output_id)
    -
    -    async def transform(self, value: Tabulator) -> Jsonifiable:
    -        # return {"values": value.values.tolist(), "columns": value.columns.tolist()}
    -        # TODO: convert with js
    -        return value.to_dict()
    +              
    62
    +63
    +64
    +65
    +66
    +67
    +68
    +69
    +70
    +71
    class render_tabulator(Renderer[Tabulator]):
    +    """A decorator for a function that returns a `Tabulator` table"""
    +
    +    def auto_output_ui(self) -> Tag:
    +        return output_tabulator(self.output_id)
    +
    +    async def transform(self, value: Tabulator) -> Jsonifiable:
    +        # return {"values": value.values.tolist(), "columns": value.columns.tolist()}
    +        # TODO: convert with js
    +        return value.to_dict()
     
    @@ -1475,29 +1454,29 @@

    Source code in pytabulator/shiny_bindings.py -
    36
    -37
    -38
    -39
    -40
    -41
    -42
    -43
    +            
    def output_tabulator(id: str):
    -    """Create an output container for a `Tabulator` table
    -
    -    Args:
    -        id (str): An output id of a `Tabulator` table.
    -    """
    -    return ui.div(
    -        tabulator_dep(),
    -        tabulator_bindings_dep,
    -        id=resolve_id(id),
    -        class_="shiny-tabulator-output",
    -    )
    +47
    +48
    +49
    +50
    +51
    +52
    +53
    +54
    def output_tabulator(id: str):
    +    """Create an output container for a `Tabulator` table
    +
    +    Args:
    +        id (str): An output id of a `Tabulator` table.
    +    """
    +    return ui.div(
    +        tabulator_dep(),
    +        tabulator_bindings_dep,
    +        id=resolve_id(id),
    +        class_="shiny-tabulator-output",
    +    )
     
    @@ -1749,8 +1728,8 @@

    -

    - TableOptions +

    + Tabulator

    @@ -1758,242 +1737,58 @@

    - Bases: BaseModel

    + Bases: object

    -

    Table options

    +

    Tabulator

    -

    Attributes:

    +

    Parameters:

    + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + - - - -
    Name Type DescriptionDefault
    index - str - -
    -

    The index of the table. Defaults to id.

    -
    -
    header_visible - bool - -
    -

    Whether to display the header of the table. Defaults to True.

    -
    -
    movable_rows - bool - -
    -

    Whether rows are movable or not. Defaults to False.

    -
    -
    group_by - Union[str, list] - -
    -

    Columns to group by. Defaults to None.

    -
    -
    height - int - -
    -

    Height in px. Defaults to 300.

    -
    -
    pagination - bool - -
    -

    Whether to enable pagination. Defaults to False.

    -
    -
    pagination_counter - str - -
    -

    Whether to display counted rows in footer. Defaults to rows.

    -
    -
    pagination_add_row - Literal['page', 'table'] - -
    -

    Where to add rows when pagination is enabled. Defaults to page.

    -
    -
    selectable - Union[str, bool, int] - -
    -

    Whether a row is selectable. An integer value sets the maximum number of rows, that can be selected. -If set to highlight, rows do not change state when clicked. Defaults to highlight.

    -
    -
    columns - list - -
    -

    Columns configuration. Defaults to None, -which means that the default configuration is used.

    -
    -
    layout - Literal['fitData', 'fitDataFill', 'fitDataStretch', 'fitDataTable', 'fitColumns'] - -
    -

    The layout of the table. Defaults to fitColumns.

    -
    -
    add_row_posdf - Literal['bottom', 'top'] + DataFrame
    -

    Where to add rows. Defaults to bottom.

    +

    A data frame.

    frozen_rows - int - -
    -

    Number of frozen rows. Defaults to Ǹone.

    -
    + required
    row_heighttable_options - int + TableOptions
    -

    Fixed height of rows. Defaults to None.

    +

    Table options.

    history - bool - -
    -

    Whether to enable history. Must be set if undo and redo is used. Defaults to False.

    -
    + {}
    -
    - Note -

    See Tabulator Setup Options for details.

    -
    - - -

    Examples:

    -
    >>> from pytabulator import TableOptions
    -
    -
    >>> table_options = TableOptions(height=500, pagination=True)
    -
    -
    Source code in pytabulator/tabulator.py -
    13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    -26
    -27
    -28
    -29
    -30
    -31
    -32
    -33
    -34
    -35
    -36
    -37
    -38
    -39
    -40
    -41
    -42
    -43
    -44
    -45
    -46
    -47
    +              
    47
     48
     49
     50
    @@ -2012,274 +1807,26 @@ 

    63 64 65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87

    class TableOptions(BaseModel):
    -    """Table options
    -
    -    Attributes:
    -        index (str, optional): The index of the table. Defaults to `id`.
    -        header_visible (bool, optional): Whether to display the header of the table. Defaults to `True`.
    -        movable_rows (bool, optional): Whether rows are movable or not. Defaults to `False`.
    -        group_by: Columns to group by. Defaults to `None`.
    -        height (int, optional): Height in px. Defaults to `300`.
    -        pagination (bool, optional): Whether to enable pagination. Defaults to `False`.
    -        pagination_counter (str, optional): Whether to display counted rows in footer. Defaults to `rows`.
    -        pagination_add_row: Where to add rows when pagination is enabled. Defaults to `page`.
    -        selectable: Whether a row is selectable. An integer value sets the maximum number of rows, that can be selected.
    -            If set to `highlight`, rows do not change state when clicked. Defaults to `highlight`.
    -        columns (list, optional): Columns configuration. Defaults to `None`,
    -            which means that the default configuration is used.
    -        layout: The layout of the table. Defaults to `fitColumns`.
    -        add_row_pos: Where to add rows. Defaults to `bottom`.
    -        frozen_rows (int, optional): Number of frozen rows. Defaults to `Ǹone`.
    -        row_height: Fixed height of rows. Defaults to `None`.
    -        history (bool, optional): Whether to enable history. Must be set if `undo` and `redo` is used. Defaults to `False`.
    -
    -    Note:
    -        See [Tabulator Setup Options](https://tabulator.info/docs/5.5/options) for details.
    -
    -    Examples:
    -        >>> from pytabulator import TableOptions
    -
    -        >>> table_options = TableOptions(height=500, pagination=True)
    -    """
    -
    -    index: str = "id"
    -    header_visible: bool = Field(True, serialization_alias="headerVisible")
    -    movable_rows: bool = Field(False, serialization_alias="movableRows")
    -    group_by: Union[str, list] = Field(None, serialization_alias="groupBy")
    -    height: Union[int, str] = None
    -    pagination: bool = False
    -    pagination_counter: str = Field("rows", serialization_alias="paginationCounter")
    -    pagination_add_row: Literal["page", "table"] = Field(
    -        "page", serialization_alias="paginationAddRow"
    -    )
    -    selectable: Union[str, bool, int] = "highlight"
    -    columns: list = None
    -    layout: Literal[
    -        "fitData", "fitDataFill", "fitDataStretch", "fitDataTable", "fitColumns"
    -    ] = "fitColumns"
    -    add_row_pos: Literal["bottom", "top"] = Field(
    -        "bottom", serialization_alias="addRowPos"
    -    )
    -    frozen_rows: int = Field(None, serialization_alias="frozenRows")
    -    row_height: int = Field(None, serialization_alias="rowHeight")
    -    resizable_column_fit: bool = Field(False, serialization_alias="resizableColumnFit")
    -    history: bool = False
    -
    -    # New features to be added in the next release
    -    """
    -    responsiveLayout: str = "hide"
    -    columnDefaults: dict = {"tooltip": True}
    -    """
    -
    -    model_config = ConfigDict(
    -        validate_assignment=True,
    -        extra="allow",
    -        # use_enum_values=True
    -    )
    -
    -    @field_validator("height")
    -    def validate_height(cls, v):
    -        if isinstance(v, int):
    -            return f"{v}px"
    -
    -        return v
    -
    -    def to_dict(self) -> dict:
    -        return self.model_dump(by_alias=True, exclude_none=True)
    -
    - - - - -
    - - - - - - - -
    - - - -

    - history: bool = False - - - class-attribute - instance-attribute - - -

    - - -
    - -

    responsiveLayout: str = "hide" -columnDefaults: dict = {"tooltip": True}

    -
    - -
    - - - - - -
    - -
    - - - - -
    - - - -

    - Tabulator - - -

    - - -
    -

    - Bases: object

    - - -

    Tabulator

    - - - -

    Parameters:

    - - - - - - - - - - - - - - - - - - - - - - - -
    NameTypeDescriptionDefault
    df - DataFrame - -
    -

    A data frame.

    -
    -
    - required -
    table_options - TableOptions - -
    -

    Table options.

    -
    -
    - None -
    - -
    - Source code in pytabulator/tabulator.py -
    class Tabulator(object):
    -    """Tabulator
    -
    -    Args:
    -        df (DataFrame): A data frame.
    -        table_options (TableOptions): Table options.
    -    """
    -
    -    def __init__(
    -        self,
    -        df: DataFrame,
    -        table_options: TableOptions | dict | TabulatorOptions = None,
    -    ) -> None:
    -        self.df = df
    -        if isinstance(table_options, TableOptions):
    -            table_options = table_options.model_dump(by_alias=True)
    -        # Legacy
    -        elif isinstance(table_options, TabulatorOptions):
    -            warn(
    -                "'TabulatorOptions' is deprecated and will be removed in one of the next releases. Use 'TableOptions' instead.",
    -                DeprecationWarning,
    -                stacklevel=2,
    -            )
    -            table_options = asdict(table_options)
    -
    -        self.table_options = table_options
    -
    -    def to_dict(self) -> dict:
    -        data = df_to_dict(self.df)
    -        data["options"] = self.table_options
    -        return data
    +66
    class Tabulator(object):
    +    """Tabulator
    +
    +    Args:
    +        df (DataFrame): A data frame.
    +        table_options (TableOptions): Table options.
    +    """
    +
    +    def __init__(
    +        self,
    +        df: DataFrame,
    +        table_options: TableOptions | dict = {},
    +    ) -> None:
    +        self.df = df
    +        self.table_options = table_options
    +
    +    def to_dict(self) -> dict:
    +        data = df_to_dict(self.df)
    +        data["options"] = jsonifiable_table_options(self.table_options)
    +        return data
     
    @@ -2956,6 +2503,345 @@

    + + + +

    + pytabulator.TableOptions + + + + dataclass + + +

    + + +
    +

    + Bases: TableOptions

    + + +

    Table options

    + + + +

    Attributes:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    add_row_pos + Literal['bottom', 'top'] + +
    +

    Where to add rows. Defaults to "bottom".

    +
    +
    columns + list + +
    +

    Column definitions.

    +
    +
    frozen_rows + int + +
    +

    Number of frozen rows. Defaults to Ǹone.

    +
    +
    group_by + Union[str, list] + +
    +

    Columns to group by. Defaults to None.

    +
    +
    header_visible + bool + +
    +

    Whether to display the header of the table. Defaults to True.

    +
    +
    height + Union[int, None] + +
    +

    The height of the table in pixels. Defaults to 311.

    +
    +
    history + bool + +
    +

    Whether to enable history. Must be set if undo and redo is used. Defaults to False.

    +
    +
    index + str + +
    +

    The field to be used as a unique index for each row. Defaults to "id".

    +
    +
    layout + Literal['fitData', 'fitDataFill', 'fitDataStretch', 'fitDataTable', 'fitColumns'] + +
    +

    The layout of the table. Defaults to "fitColumns".

    +
    +
    movable_rows + bool + +
    +

    Whether rows are movable. Defaults to False.

    +
    +
    pagination_add_row + Literal['page', 'table'] + +
    +

    Where to add rows when pagination is enabled. Defaults to "page".

    +
    +
    pagination + bool + +
    +

    Whether to enable pagination. Defaults to False.

    +
    +
    pagination_counter + str + +
    +

    Whether to display counted rows in footer. Defaults to "rows".

    +
    +
    resizable_column_fit + bool + +
    +

    Maintain total column width when resizing a column. Defaults to False.

    +
    +
    row_height + int + +
    +

    Fixed height for rows. Defaults to None.

    +
    +
    selectable + Union[str, bool, int] + +
    +

    Whether a row is selectable. An integer value sets the maximum number of rows, that can be selected. +If set to "highlight", rows do not change their state when they are clicked. Defaults to "highlight".

    +
    +
    + +
    + Source code in pytabulator/_table_options_dc.py +
    10
    +11
    +12
    +13
    +14
    +15
    +16
    +17
    +18
    +19
    +20
    +21
    +22
    +23
    +24
    +25
    +26
    +27
    +28
    +29
    +30
    +31
    +32
    +33
    +34
    +35
    +36
    +37
    +38
    +39
    +40
    +41
    +42
    +43
    +44
    +45
    +46
    +47
    +48
    +49
    +50
    +51
    +52
    +53
    +54
    +55
    +56
    +57
    +58
    +59
    @dataclass
    +class TableOptionsDC(TableOptions):
    +    """Table options
    +
    +    Attributes:
    +        add_row_pos: Where to add rows. Defaults to `"bottom"`.
    +        columns: Column definitions.
    +        frozen_rows: Number of frozen rows. Defaults to `Ǹone`.
    +        group_by: Columns to group by. Defaults to `None`.
    +        header_visible: Whether to display the header of the table. Defaults to `True`.
    +        height: The height of the table in pixels. Defaults to `311`.
    +        history: Whether to enable history. Must be set if `undo` and `redo` is used. Defaults to `False`.
    +        index: The field to be used as a unique index for each row. Defaults to `"id"`.
    +        layout: The layout of the table. Defaults to `"fitColumns"`.
    +        movable_rows: Whether rows are movable. Defaults to `False`.
    +        pagination_add_row: Where to add rows when pagination is enabled. Defaults to `"page"`.
    +        pagination: Whether to enable pagination. Defaults to `False`.
    +        pagination_counter: Whether to display counted rows in footer. Defaults to `"rows"`.
    +        resizable_column_fit: Maintain total column width when resizing a column. Defaults to `False`.
    +        row_height: Fixed height for rows. Defaults to `None`.
    +        selectable: Whether a row is selectable. An integer value sets the maximum number of rows, that can be selected.
    +            If set to `"highlight"`, rows do not change their state when they are clicked. Defaults to `"highlight"`.
    +    """
    +
    +    add_row_pos: Literal["bottom", "top"] = "bottom"
    +    columns: list = None
    +    frozen_rows: int = None
    +    group_by: Union[str, list] = None
    +    header_visible: bool = True
    +    height: Union[int, None] = 311
    +    history: bool = False
    +    index: str = "id"
    +    layout: Literal[
    +        "fitData", "fitDataFill", "fitDataStretch", "fitDataTable", "fitColumns"
    +    ] = "fitColumns"
    +    movable_rows: bool = False
    +    pagination_add_row: Literal["page", "table"] = "page"
    +    pagination: bool = False
    +    pagination_counter: str = "rows"
    +    resizable_column_fit: bool = False
    +    row_height: int = None
    +    selectable: Union[str, bool, int] = "highlight"
    +
    +    def to_dict(self):
    +        return asdict(
    +            self,
    +            dict_factory=lambda x: {
    +                snake_to_camel_case(k): v for (k, v) in x if v is not None
    +            },
    +        )
    +
    +
    + + + +
    + + + + + + + + + + + +
    + +
    + + +
    + diff --git a/changelog/index.html b/changelog/index.html index 8463eb1..6083fd4 100644 --- a/changelog/index.html +++ b/changelog/index.html @@ -223,7 +223,7 @@
  • - + Examples @@ -439,27 +439,36 @@
  • Basic usage

    -

    Shiny Express example:

    +

    Shiny Express:

    import pandas as pd
     from pytabulator import TableOptions, render_data_frame
     from shiny import render
    @@ -803,6 +824,33 @@ 

    Basic usage

    "https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv" )
    +

    Shiny core:

    +
    import pandas as pd
    +from pytabulator import TableOptions, Tabulator, output_tabulator, render_tabulator
    +from shiny import App, render, ui
    +
    +app_ui = ui.page_fluid(
    +    ui.output_text_verbatim("txt", placeholder=True),
    +    output_tabulator("tabulator"),
    +)
    +
    +
    +def server(input, output, session):
    +    @render_tabulator
    +    def tabulator():
    +        df = pd.read_csv(
    +            "https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv"
    +        )
    +        return Tabulator(df, table_options=TableOptions(height=311))
    +
    +    @render.code
    +    async def txt():
    +        print(input.tabulator_row_clicked())
    +        return str(input.tabulator_row_clicked())
    +
    +
    +app = App(app_ui, server)
    +
    diff --git a/objects.inv b/objects.inv index 82073ec..051d701 100644 Binary files a/objects.inv and b/objects.inv differ diff --git a/search/search_index.json b/search/search_index.json index 3c482f3..58dc050 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Welcome to Tabulator for Python","text":"

    Tabulator for Python provides Shiny for Python bindings for Tabulator JS.

    "},{"location":"#installation","title":"Installation","text":"
    # Stable\npip install pytabulator\n\n# Dev\npip install git+https://github.com/eodaGmbH/py-tabulator\n
    "},{"location":"#basic-usage","title":"Basic usage","text":"

    Shiny Express example:

    import pandas as pd\nfrom pytabulator import TableOptions, render_data_frame\nfrom shiny import render\nfrom shiny.express import input, ui\n\nui.div(\"Click on row to print name\", style=\"padding: 10px;\")\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\n@render_data_frame(table_options=TableOptions(height=500))\ndef tabulator():\n    return pd.read_csv(\n        \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n    )\n
    "},{"location":"api/","title":"API Documentation","text":""},{"location":"api/#basic-usage","title":"Basic usage","text":"
    import pandas as pd\nfrom pytabulator import TableOptions, render_data_frame\nfrom shiny import render\nfrom shiny.express import input, ui\n\nui.div(\"Click on row to print name\", style=\"padding: 10px;\")\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\n@render_data_frame(table_options=TableOptions(height=500))\ndef tabulator():\n    return pd.read_csv(\n        \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n    )\n

    See also detailed example.

    "},{"location":"api/#pytabulator.shiny_bindings","title":"pytabulator.shiny_bindings","text":""},{"location":"api/#pytabulator.shiny_bindings.render_data_frame","title":"render_data_frame","text":"

    Bases: Renderer[DataFrame]

    A decorator for a function that returns a DataFrame

    Parameters:

    Name Type Description Default table_options TableOptions

    Table options.

    TableOptions() Source code in pytabulator/shiny_bindings.py
    class render_data_frame(Renderer[DataFrame]):\n    \"\"\"A decorator for a function that returns a `DataFrame`\n\n    Args:\n        table_options (TableOptions): Table options.\n    \"\"\"\n\n    editor: bool\n\n    def auto_output_ui(self) -> Tag:\n        return output_tabulator(self.output_id)\n\n    def __init__(\n        self,\n        _fn: ValueFn[DataFrame] = None,\n        *,\n        table_options: TableOptions | TabulatorOptions = TableOptions(),\n    ) -> None:\n        super().__init__(_fn)\n        self.table_options = table_options\n\n    async def render(self) -> Jsonifiable:\n        df = await self.fn()\n        # return {\"values\": value.values.tolist(), \"columns\": value.columns.tolist()}\n        # TODO: convert with js\n        data = df_to_dict(df)\n        data[\"options\"] = (\n            asdict(self.table_options)\n            if isinstance(self.table_options, TabulatorOptions)\n            else self.table_options.model_dump(by_alias=True)\n        )\n        return data\n
    "},{"location":"api/#pytabulator.shiny_bindings.render_tabulator","title":"render_tabulator","text":"

    Bases: Renderer[Tabulator]

    A decorator for a function that returns a Tabulator table

    Source code in pytabulator/shiny_bindings.py
    class render_tabulator(Renderer[Tabulator]):\n    \"\"\"A decorator for a function that returns a `Tabulator` table\"\"\"\n\n    def auto_output_ui(self) -> Tag:\n        return output_tabulator(self.output_id)\n\n    async def transform(self, value: Tabulator) -> Jsonifiable:\n        # return {\"values\": value.values.tolist(), \"columns\": value.columns.tolist()}\n        # TODO: convert with js\n        return value.to_dict()\n
    "},{"location":"api/#pytabulator.shiny_bindings.output_tabulator","title":"output_tabulator(id)","text":"

    Create an output container for a Tabulator table

    Parameters:

    Name Type Description Default id str

    An output id of a Tabulator table.

    required Source code in pytabulator/shiny_bindings.py
    def output_tabulator(id: str):\n    \"\"\"Create an output container for a `Tabulator` table\n\n    Args:\n        id (str): An output id of a `Tabulator` table.\n    \"\"\"\n    return ui.div(\n        tabulator_dep(),\n        tabulator_bindings_dep,\n        id=resolve_id(id),\n        class_=\"shiny-tabulator-output\",\n    )\n
    "},{"location":"api/#pytabulator.utils","title":"pytabulator.utils","text":""},{"location":"api/#pytabulator.utils.create_columns","title":"create_columns(df, default_filter=False, default_editor=False, updates={})","text":"

    Create columns configuration from a data frame

    Parameters:

    Name Type Description Default df DataFrame

    The data frame to create columns from.

    required default_filter bool

    Whether to add a default header filter to each column.

    False default_editor bool

    Whether to add a default editor to each column.

    False updates dict

    Dictionary of updates that overwrite the default settings or add additional settings the columns.

    {} Source code in pytabulator/utils.py
    def create_columns(\n    df: DataFrame,\n    default_filter: bool = False,\n    default_editor: bool = False,\n    updates: dict = {},\n) -> list:\n    \"\"\"Create columns configuration from a data frame\n\n    Args:\n        df (DataFrame): The data frame to create columns from.\n        default_filter (bool): Whether to add a default header filter to each column.\n        default_editor (bool): Whether to add a default editor to each column.\n        updates (dict): Dictionary of updates that overwrite the default settings or add additional settings the columns.\n    \"\"\"\n    # (hozAlign, headerFilter, editor)\n    setup = [\n        (\n            (\"right\", \"number\", \"number\")\n            if dtype in [int, float]\n            else (\"left\", \"input\", \"input\")\n        )\n        for dtype in df.dtypes.tolist()\n    ]\n    columns = [\n        {\"title\": column, \"field\": column, \"hozAlign\": setup[i][0]}\n        for i, column in enumerate(df.columns)\n    ]\n\n    if default_filter:\n        for i, column in enumerate(columns):\n            column[\"headerFilter\"] = setup[i][1]\n\n    if default_editor:\n        for i, column in enumerate(columns):\n            column[\"editor\"] = setup[i][2]\n\n    for key in updates:\n        for column in columns:\n            if column[\"field\"] == key:\n                column.update(updates[key])\n\n    return columns\n
    "},{"location":"api/#pytabulator.tabulator","title":"pytabulator.tabulator","text":""},{"location":"api/#pytabulator.tabulator.TableOptions","title":"TableOptions","text":"

    Bases: BaseModel

    Table options

    Attributes:

    Name Type Description index str

    The index of the table. Defaults to id.

    header_visible bool

    Whether to display the header of the table. Defaults to True.

    movable_rows bool

    Whether rows are movable or not. Defaults to False.

    group_by Union[str, list]

    Columns to group by. Defaults to None.

    height int

    Height in px. Defaults to 300.

    pagination bool

    Whether to enable pagination. Defaults to False.

    pagination_counter str

    Whether to display counted rows in footer. Defaults to rows.

    pagination_add_row Literal['page', 'table']

    Where to add rows when pagination is enabled. Defaults to page.

    selectable Union[str, bool, int]

    Whether a row is selectable. An integer value sets the maximum number of rows, that can be selected. If set to highlight, rows do not change state when clicked. Defaults to highlight.

    columns list

    Columns configuration. Defaults to None, which means that the default configuration is used.

    layout Literal['fitData', 'fitDataFill', 'fitDataStretch', 'fitDataTable', 'fitColumns']

    The layout of the table. Defaults to fitColumns.

    add_row_pos Literal['bottom', 'top']

    Where to add rows. Defaults to bottom.

    frozen_rows int

    Number of frozen rows. Defaults to \u01f8one.

    row_height int

    Fixed height of rows. Defaults to None.

    history bool

    Whether to enable history. Must be set if undo and redo is used. Defaults to False.

    Note

    See Tabulator Setup Options for details.

    Examples:

    >>> from pytabulator import TableOptions\n
    >>> table_options = TableOptions(height=500, pagination=True)\n
    Source code in pytabulator/tabulator.py
    class TableOptions(BaseModel):\n    \"\"\"Table options\n\n    Attributes:\n        index (str, optional): The index of the table. Defaults to `id`.\n        header_visible (bool, optional): Whether to display the header of the table. Defaults to `True`.\n        movable_rows (bool, optional): Whether rows are movable or not. Defaults to `False`.\n        group_by: Columns to group by. Defaults to `None`.\n        height (int, optional): Height in px. Defaults to `300`.\n        pagination (bool, optional): Whether to enable pagination. Defaults to `False`.\n        pagination_counter (str, optional): Whether to display counted rows in footer. Defaults to `rows`.\n        pagination_add_row: Where to add rows when pagination is enabled. Defaults to `page`.\n        selectable: Whether a row is selectable. An integer value sets the maximum number of rows, that can be selected.\n            If set to `highlight`, rows do not change state when clicked. Defaults to `highlight`.\n        columns (list, optional): Columns configuration. Defaults to `None`,\n            which means that the default configuration is used.\n        layout: The layout of the table. Defaults to `fitColumns`.\n        add_row_pos: Where to add rows. Defaults to `bottom`.\n        frozen_rows (int, optional): Number of frozen rows. Defaults to `\u01f8one`.\n        row_height: Fixed height of rows. Defaults to `None`.\n        history (bool, optional): Whether to enable history. Must be set if `undo` and `redo` is used. Defaults to `False`.\n\n    Note:\n        See [Tabulator Setup Options](https://tabulator.info/docs/5.5/options) for details.\n\n    Examples:\n        >>> from pytabulator import TableOptions\n\n        >>> table_options = TableOptions(height=500, pagination=True)\n    \"\"\"\n\n    index: str = \"id\"\n    header_visible: bool = Field(True, serialization_alias=\"headerVisible\")\n    movable_rows: bool = Field(False, serialization_alias=\"movableRows\")\n    group_by: Union[str, list] = Field(None, serialization_alias=\"groupBy\")\n    height: Union[int, str] = None\n    pagination: bool = False\n    pagination_counter: str = Field(\"rows\", serialization_alias=\"paginationCounter\")\n    pagination_add_row: Literal[\"page\", \"table\"] = Field(\n        \"page\", serialization_alias=\"paginationAddRow\"\n    )\n    selectable: Union[str, bool, int] = \"highlight\"\n    columns: list = None\n    layout: Literal[\n        \"fitData\", \"fitDataFill\", \"fitDataStretch\", \"fitDataTable\", \"fitColumns\"\n    ] = \"fitColumns\"\n    add_row_pos: Literal[\"bottom\", \"top\"] = Field(\n        \"bottom\", serialization_alias=\"addRowPos\"\n    )\n    frozen_rows: int = Field(None, serialization_alias=\"frozenRows\")\n    row_height: int = Field(None, serialization_alias=\"rowHeight\")\n    resizable_column_fit: bool = Field(False, serialization_alias=\"resizableColumnFit\")\n    history: bool = False\n\n    # New features to be added in the next release\n    \"\"\"\n    responsiveLayout: str = \"hide\"\n    columnDefaults: dict = {\"tooltip\": True}\n    \"\"\"\n\n    model_config = ConfigDict(\n        validate_assignment=True,\n        extra=\"allow\",\n        # use_enum_values=True\n    )\n\n    @field_validator(\"height\")\n    def validate_height(cls, v):\n        if isinstance(v, int):\n            return f\"{v}px\"\n\n        return v\n\n    def to_dict(self) -> dict:\n        return self.model_dump(by_alias=True, exclude_none=True)\n
    "},{"location":"api/#pytabulator.tabulator.TableOptions.history","title":"history: bool = False class-attribute instance-attribute","text":"

    responsiveLayout: str = \"hide\" columnDefaults: dict = {\"tooltip\": True}

    "},{"location":"api/#pytabulator.tabulator.Tabulator","title":"Tabulator","text":"

    Bases: object

    Tabulator

    Parameters:

    Name Type Description Default df DataFrame

    A data frame.

    required table_options TableOptions

    Table options.

    None Source code in pytabulator/tabulator.py
    class Tabulator(object):\n    \"\"\"Tabulator\n\n    Args:\n        df (DataFrame): A data frame.\n        table_options (TableOptions): Table options.\n    \"\"\"\n\n    def __init__(\n        self,\n        df: DataFrame,\n        table_options: TableOptions | dict | TabulatorOptions = None,\n    ) -> None:\n        self.df = df\n        if isinstance(table_options, TableOptions):\n            table_options = table_options.model_dump(by_alias=True)\n        # Legacy\n        elif isinstance(table_options, TabulatorOptions):\n            warn(\n                \"'TabulatorOptions' is deprecated and will be removed in one of the next releases. Use 'TableOptions' instead.\",\n                DeprecationWarning,\n                stacklevel=2,\n            )\n            table_options = asdict(table_options)\n\n        self.table_options = table_options\n\n    def to_dict(self) -> dict:\n        data = df_to_dict(self.df)\n        data[\"options\"] = self.table_options\n        return data\n
    "},{"location":"api/#pytabulator.tabulator_context","title":"pytabulator.tabulator_context","text":""},{"location":"api/#pytabulator.tabulator_context.TabulatorContext","title":"TabulatorContext","text":"

    Bases: object

    Table context

    Source code in pytabulator/tabulator_context.py
    class TabulatorContext(object):\n    \"\"\"Table context\"\"\"\n\n    def __init__(self, id: str, session: Session = None) -> None:\n        self.id = id\n        self._session = require_active_session(session)\n        self._message_queue = []\n\n    async def __aenter__(self):\n        return self\n\n    async def __aexit__(self, exc_type, exc_val, exc_tb):\n        await self.render()\n\n    async def render(self):\n        await self._session.send_custom_message(\n            f\"tabulator-{self.id}\", {\"id\": self.id, \"calls\": self._message_queue}\n        )\n\n    def add_call(self, method_name: str, *args) -> None:\n        \"\"\"Add a method call that is executed on the table instance\n\n        Args:\n            method_name (str): The name of the method to be executed.\n            *args (any): The arguments to be passed to the table method.\n        \"\"\"\n        call = [method_name, args]\n        self._message_queue.append(call)\n\n    def trigger_download(\n        self, type: Literal[\"csv\", \"json\"] = \"csv\", file_name: str = None\n    ) -> None:\n        \"\"\"Trigger download\n\n        Args:\n            type (str): The data type of file to be downloaded.\n            file_name (str): The file name.\n        \"\"\"\n        if not file_name:\n            file_name = f\"tabulator-data.{type}\"\n\n        self.add_call(\"download\", type, file_name)\n\n    def add_row(self, row: dict = {}) -> None:\n        \"\"\"Add a row to the table\n\n        Args:\n            row (dict): Row data to add.\n        \"\"\"\n        self.add_call(\"addRow\", row)\n\n    def delete_row(self, index: int | str) -> None:\n        \"\"\"Delete a row from the table\n\n        Args:\n            index: The index of the row to delete.\n        \"\"\"\n        self.add_call(\"deleteRow\", index)\n\n    def delete_selected_rows(self) -> None:\n        \"\"\"Delete selected rows from table\"\"\"\n        self.add_call(\"deleteSelectedRows\")\n\n    def undo(self) -> None:\n        \"\"\"Trigger undo\"\"\"\n        self.add_call(\"undo\")\n\n    def redo(self) -> None:\n        \"\"\"Trigger redo\"\"\"\n        self.add_call(\"redo\")\n\n    def trigger_get_data(self) -> None:\n        \"\"\"Trigger sending data\"\"\"\n        self.add_call(\"getData\")\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.add_call","title":"add_call(method_name, *args)","text":"

    Add a method call that is executed on the table instance

    Parameters:

    Name Type Description Default method_name str

    The name of the method to be executed.

    required *args any

    The arguments to be passed to the table method.

    () Source code in pytabulator/tabulator_context.py
    def add_call(self, method_name: str, *args) -> None:\n    \"\"\"Add a method call that is executed on the table instance\n\n    Args:\n        method_name (str): The name of the method to be executed.\n        *args (any): The arguments to be passed to the table method.\n    \"\"\"\n    call = [method_name, args]\n    self._message_queue.append(call)\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.add_row","title":"add_row(row={})","text":"

    Add a row to the table

    Parameters:

    Name Type Description Default row dict

    Row data to add.

    {} Source code in pytabulator/tabulator_context.py
    def add_row(self, row: dict = {}) -> None:\n    \"\"\"Add a row to the table\n\n    Args:\n        row (dict): Row data to add.\n    \"\"\"\n    self.add_call(\"addRow\", row)\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.delete_row","title":"delete_row(index)","text":"

    Delete a row from the table

    Parameters:

    Name Type Description Default index int | str

    The index of the row to delete.

    required Source code in pytabulator/tabulator_context.py
    def delete_row(self, index: int | str) -> None:\n    \"\"\"Delete a row from the table\n\n    Args:\n        index: The index of the row to delete.\n    \"\"\"\n    self.add_call(\"deleteRow\", index)\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.delete_selected_rows","title":"delete_selected_rows()","text":"

    Delete selected rows from table

    Source code in pytabulator/tabulator_context.py
    def delete_selected_rows(self) -> None:\n    \"\"\"Delete selected rows from table\"\"\"\n    self.add_call(\"deleteSelectedRows\")\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.redo","title":"redo()","text":"

    Trigger redo

    Source code in pytabulator/tabulator_context.py
    def redo(self) -> None:\n    \"\"\"Trigger redo\"\"\"\n    self.add_call(\"redo\")\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.trigger_download","title":"trigger_download(type='csv', file_name=None)","text":"

    Trigger download

    Parameters:

    Name Type Description Default type str

    The data type of file to be downloaded.

    'csv' file_name str

    The file name.

    None Source code in pytabulator/tabulator_context.py
    def trigger_download(\n    self, type: Literal[\"csv\", \"json\"] = \"csv\", file_name: str = None\n) -> None:\n    \"\"\"Trigger download\n\n    Args:\n        type (str): The data type of file to be downloaded.\n        file_name (str): The file name.\n    \"\"\"\n    if not file_name:\n        file_name = f\"tabulator-data.{type}\"\n\n    self.add_call(\"download\", type, file_name)\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.trigger_get_data","title":"trigger_get_data()","text":"

    Trigger sending data

    Source code in pytabulator/tabulator_context.py
    def trigger_get_data(self) -> None:\n    \"\"\"Trigger sending data\"\"\"\n    self.add_call(\"getData\")\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.undo","title":"undo()","text":"

    Trigger undo

    Source code in pytabulator/tabulator_context.py
    def undo(self) -> None:\n    \"\"\"Trigger undo\"\"\"\n    self.add_call(\"undo\")\n
    "},{"location":"changelog/","title":"Changelog for Tabulator for Python","text":""},{"location":"changelog/#pytabulator-v022","title":"pytabulator v0.2.2","text":"
    • Add themes
    • Add optional support for xlsx exports via sheetjs
    "},{"location":"changelog/#pytabulator-v021-2024-04-03","title":"pytabulator v0.2.1 (2024-04-03)","text":"
    • Set version of pandas requirement to >=1.5.3
    • Allow extra arguments in TableOptions
    "},{"location":"changelog/#pytabulator-v020-2024-04-02","title":"pytabulator v0.2.0 (2024-04-02)","text":"

    Initial PyPI release

    • Add docs
    • Rename TabulatorOptions to TableOptions
    • Use Pydantic for TableOptions
    • Add more input events
    • Add detailed example
    • Add utility function to create columns configuration from data frame
    "},{"location":"changelog/#pytabulator-v010-2024-01-31-pre-release","title":"pytabulator v0.1.0 (2024-01-31, Pre-release)","text":"

    Initial release

    "},{"location":"columns/","title":"Columns and filters","text":"

    With the columns argument of TableOptions you can configure the columns of the table.

    See Tabulator JS columns docs for a complete list of available setup options.

    "},{"location":"columns/#default-definition","title":"Default definition","text":"

    If no columns arguments is provided, title and field is set to the column name of the data frame. Furthermore, the alignment is set to right for numeric columns.

    from pandas import DataFrame\nfrom pytabulator import render_data_frame\n\ndata = [[\"Peter\", 10], [\"Hans\", 12]]\ndf = DataFrame(data, columns=[\"Name\", \"Age\"])\n\n@render_data_frame\ndef tabulator():\n    return df\n

    The following definition is created by default for the above data frame:

    columns = [\n    {\"title\": \"Name\", \"field\": \"Name\", \"horizAlign\": \"left\"},\n    {\"title\": \"Age\", \"field\": \"Age\", \"horizAlign\": \"right\"}\n]\n
    "},{"location":"columns/#customize-default-configuration","title":"Customize default configuration","text":"

    With create_columns you can customize the default configuration:

    from pandas import DataFrame\nfrom pytabulator import TableOptions\nfrom pytabulator.utils import create_columns\n\ndata = [[\"Peter\", 10, 102.5], [\"Hans\", 12, 200.9]]\ndf = DataFrame(data, columns=[\"Name\", \"Age\", \"JustANumber\"])\n\ntable_options = TableOptions(\n    columns=create_columns(\n        df,\n        default_filter=True,\n        default_editor=True,\n        updates={\"JustANumber\": {\"formatter\": \"progress\", \"horizAlign\": \"left\"}})\n)\n

    In the example above with default_editor=True all columns are set to editable and with default_filter=True a header filter is added to all columns. For numeric columns the editor and filter mode is set to number.

    The updates arguments allows you to overwrite any defaults set for a column. In this case the formatter of the numeric column JustANumber is set to progress and the alignment is changed from right to left.

    "},{"location":"columns/#calculations","title":"Calculations","text":"

    Calculations can be set with the bottomCalc parameter:

    from pytabulator import TableOptions\n\ncolumns = [\n    {\"title\": \"Name\", \"field\": \"Name\", \"horizAlign\": \"left\"},\n    {\"title\": \"Age\", \"field\": \"Age\", \"horizAlign\": \"right\", \"bottomCalc\": \"avg\"}\n]\n\ntable_options = TableOptions(columns=columns)\n
    "},{"location":"columns/#filters","title":"Filters","text":"

    You can add a filter to the columns with the headerFilter parameter:

    from pytabulator import TableOptions\n\ncolumns = [\n    {\n        \"title\": \"Name\",\n        \"field\": \"Name\",\n        \"horizAlign\": \"left\",\n        \"headerFilter\": True\n    },\n    {\n        \"title\": \"Age\",\n        \"field\": \"Age\",\n        \"horizAlign\": \"right\",\n        \"bottomCalc\": \"avg\",\n        \"headerFilter\": \"number\"\n    }\n]\n\ntable_options = TableOptions(columns=columns)\n

    Shiny Express example:

    import pandas as pd\nfrom pytabulator import TableOptions, Tabulator, TabulatorContext, render_tabulator\nfrom shiny import reactive, render\nfrom shiny.express import input, ui\n\ndf = pd.read_csv(\n    \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n)\n\n# Setup\n#\ncolumns = [\n    {\n        \"title\": \"Name\",\n        \"field\": \"Name\",\n        \"headerFilter\": True,\n        \"headerFilterPlaceholder\": \"Find a Person...\",\n        # \"headerFilterLiveFilter\": False,\n    },\n    {\n        \"title\": \"Survived\",\n        \"field\": \"Survived\",\n        \"hozAlign\": \"right\",\n        \"headerFilter\": \"list\",\n        \"headerFilterParams\": {\n            \"values\": {\n                \"1\": \"Survived\",\n                \"0\": \"Died\",\n            }\n        },\n    },\n]\n\ntable_options = TableOptions(\n    height=600, pagination=True, layout=\"fitDataTable\", columns=columns\n)\n\n# Shiny Express app\n#\nui.div(\n    ui.input_action_button(\"clear_filter\", \"Clear Filter\"),\n    style=\"padding-bottom: 10px; padding-top: 10px;\",\n)\n\n\n@reactive.Effect\n@reactive.event(input.clear_filter)\nasync def clear_filter():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.add_call(\"clearHeaderFilter\")\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_data_filtered())\n    return f\"Number of search result: {len(input.tabulator_data_filtered())}\"\n\n\n@render_tabulator\ndef tabulator():\n    return Tabulator(df, table_options)\n
    "},{"location":"columns/#editor","title":"Editor","text":"

    Set editor to True, \"input\" or \"number\" to make the cells of a column editable:

    columns = [\n    {\"title\": \"Name\", \"field\": \"Name\", \"horizAlign\": \"left\", \"editor\": True},\n    {\"title\": \"Age\", \"field\": \"Age\", \"horizAlign\": \"right\", \"editor\": \"number\"}\n]\n
    "},{"location":"events/","title":"Events and triggers","text":""},{"location":"events/#events","title":"Events","text":"

    Tabulator for Python provides the following reactive inputs:

    • input.{output_id}_row_clicked event: Sends the data of the clicked row.
    • input.{output_id}_row_edited event: Sends the data of the edited row. This event is fired each time a cell of the row is edited.
    • input.{output_id}_rows_selected event: Sends the data of all selected rows. This event is fired each time a new row is selected.
    • input.{output_id}_data event: Sends the complete data of the table. This event must be triggered from Shiny.
    • input.{output_id}_data_filtered event: Sends data of filtered rows. This event is triggered each time a filter is applied.
    from shiny import render\nfrom pandas import read_csv\nfrom pytabulator import render_data_frame\n\n\n# in this case (Shiny Express) the function name corresponds to the 'output_id'\n# output_id = \"tabulator\"\n#\n# on-row-clicked event: input.tabulator_row_clicked\n# on-row-edited event: input.tabulator_row_edited\n#\n@render_data_frame\ndef tabulator():\n    return read_csv(\"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\")\n\n\n# row-on-click event\n#\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\n# row-edited event\n#\n@render.code\ndef row_edited():\n    data = input.tabulator_row_edited()\n    print(data)\n    return f\"{data['Name']}, {data['Sex']}\"\n
    "},{"location":"events/#triggers","title":"Triggers","text":"

    With TabulatorContext you can trigger events on the table object. TabulatorContext must be used in an async function:

    from shiny import reactive\nfrom shiny.express import ui\nfrom pytabulator import TabulatorContext\n\nui.input_action_button(\"trigger_download\", \"Download\")\nui.input_action_button(\"add_row\", \"Add row\")\n\n\n# Trigger download of csv file\n#\n@reactive.Effect\n@reactive.event(input.trigger_download)\nasync def trigger_download():\n    print(\"download triggered\")\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_download(\"csv\")\n\n\n# Add a row to the table\n#\n@reactive.Effect\n@reactive.event(input.add_row)\nasync def add_row():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.add_row({\"Name\": \"Hans\", \"Sex\": \"male\"})\n
    "},{"location":"events/#detailed-example","title":"Detailed example","text":"
    from random import randrange\n\nimport pandas as pd\nfrom pytabulator import TableOptions, Tabulator, TabulatorContext, render_tabulator\nfrom pytabulator.utils import create_columns\nfrom shiny import reactive, render\nfrom shiny.express import input, ui\n\n# Fetch data\n#\ndf = pd.read_csv(\n    \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n)[[\"PassengerId\", \"Name\", \"Pclass\", \"Sex\", \"Age\", \"Fare\", \"Survived\"]]\n\n# Setup\n#\ntable_options = TableOptions(\n    columns=create_columns(\n        df,\n        default_filter=True,\n        default_editor=True,\n        updates={\n            \"Pclass\": {\n                \"formatter\": \"star\",\n                \"formatterParams\": {\"stars\": 3},\n                \"hozAlign\": \"center\",\n            },\n            \"Survived\": {\"formatter\": \"tickCross\"},\n            \"Fare\": {\"formatter\": \"progress\", \"hozAlign\": \"left\"},\n        },\n    ),\n    height=413,\n    pagination=True,\n    pagination_add_row=\"table\",\n    layout=\"fitColumns\",\n    index=\"PassengerId\",\n    add_row_pos=\"top\",\n    selectable=True,\n    history=True,\n)\n\n# Shiny Express App\n#\nwith ui.div(style=\"padding-top: 0px;\"):\n    ui.input_action_button(\"trigger_download\", \"Download\")\n    ui.input_action_button(\"add_row\", \"Add row\")\n    ui.input_action_button(\"delete_selected_rows\", \"Delete selected rows\")\n    ui.input_action_button(\"undo\", \"Undo\")\n    ui.input_action_button(\"redo\", \"Redo\")\n    ui.input_action_button(\"trigger_get_data\", \"Submit data\")\n\nui.div(\n    ui.input_text(\"name\", \"Click on 'Add row' to add the Person to the table.\"),\n    style=\"padding-top: 20px;\",\n)\nui.div(\"Click on a row to print the name of the person.\", style=\"padding: 10px;\"),\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\nui.div(\n    \"Select multiple rows to print the names of the selected persons.\",\n    style=\"padding: 10px;\",\n),\n\n\n@render.code\ndef selected_rows():\n    data = input.tabulator_rows_selected()\n    output = [item[\"Name\"] for item in data]\n    return \"\\n\".join(output)\n\n\n@render_tabulator\ndef tabulator():\n    return Tabulator(df, table_options)\n\n\n@reactive.Effect\n@reactive.event(input.trigger_download)\nasync def trigger_download():\n    print(\"download triggered\")\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_download(\"csv\")\n\n\n@reactive.Effect\n@reactive.event(input.add_row)\nasync def add_row():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.add_row(\n            {\n                \"Name\": input.name() or \"Hans\",\n                \"Age\": randrange(55),\n                \"Survived\": randrange(2),\n                \"PassengerId\": randrange(10000, 20000, 1),\n                \"SibSp\": randrange(9),\n            }\n        )\n\n\n@reactive.Effect\n@reactive.event(input.delete_selected_rows)\nasync def delete_selected_rows():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.delete_selected_rows()\n\n\n@reactive.Effect\n@reactive.event(input.undo)\nasync def undo():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.undo()\n\n\n@reactive.Effect\n@reactive.event(input.redo)\nasync def redo():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.redo()\n\n\n@reactive.Effect\n@reactive.event(input.trigger_get_data)\nasync def trigger_get_data():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_get_data()\n\n\n@reactive.Effect\n@reactive.event(input.tabulator_data)\ndef tabulator_data():\n    print(input.tabulator_data()[0])\n
    "},{"location":"example/","title":"Detailed example","text":"

    This example uses Shiny Express.

    shiny run docs/examples/getting_started/shiny_express_all.py\n
    from random import randrange\n\nimport pandas as pd\nfrom pytabulator import TableOptions, Tabulator, TabulatorContext, render_tabulator\nfrom pytabulator.utils import create_columns\nfrom shiny import reactive, render\nfrom shiny.express import input, ui\n\n# Fetch data\n#\ndf = pd.read_csv(\n    \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n)[[\"PassengerId\", \"Name\", \"Pclass\", \"Sex\", \"Age\", \"Fare\", \"Survived\"]]\n\n# Setup\n#\ntable_options = TableOptions(\n    columns=create_columns(\n        df,\n        default_filter=True,\n        default_editor=True,\n        updates={\n            \"Pclass\": {\n                \"formatter\": \"star\",\n                \"formatterParams\": {\"stars\": 3},\n                \"hozAlign\": \"center\",\n            },\n            \"Survived\": {\"formatter\": \"tickCross\"},\n            \"Fare\": {\"formatter\": \"progress\", \"hozAlign\": \"left\"},\n        },\n    ),\n    height=413,\n    pagination=True,\n    pagination_add_row=\"table\",\n    layout=\"fitColumns\",\n    index=\"PassengerId\",\n    add_row_pos=\"top\",\n    selectable=True,\n    history=True,\n)\n\n# Shiny Express App\n#\nwith ui.div(style=\"padding-top: 0px;\"):\n    ui.input_action_button(\"trigger_download\", \"Download\")\n    ui.input_action_button(\"add_row\", \"Add row\")\n    ui.input_action_button(\"delete_selected_rows\", \"Delete selected rows\")\n    ui.input_action_button(\"undo\", \"Undo\")\n    ui.input_action_button(\"redo\", \"Redo\")\n    ui.input_action_button(\"trigger_get_data\", \"Submit data\")\n\nui.div(\n    ui.input_text(\"name\", \"Click on 'Add row' to add the Person to the table.\"),\n    style=\"padding-top: 20px;\",\n)\nui.div(\"Click on a row to print the name of the person.\", style=\"padding: 10px;\"),\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\nui.div(\n    \"Select multiple rows to print the names of the selected persons.\",\n    style=\"padding: 10px;\",\n),\n\n\n@render.code\ndef selected_rows():\n    data = input.tabulator_rows_selected()\n    output = [item[\"Name\"] for item in data]\n    return \"\\n\".join(output)\n\n\n@render_tabulator\ndef tabulator():\n    return Tabulator(df, table_options)\n\n\n@reactive.Effect\n@reactive.event(input.trigger_download)\nasync def trigger_download():\n    print(\"download triggered\")\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_download(\"csv\")\n\n\n@reactive.Effect\n@reactive.event(input.add_row)\nasync def add_row():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.add_row(\n            {\n                \"Name\": input.name() or \"Hans\",\n                \"Age\": randrange(55),\n                \"Survived\": randrange(2),\n                \"PassengerId\": randrange(10000, 20000, 1),\n                \"SibSp\": randrange(9),\n            }\n        )\n\n\n@reactive.Effect\n@reactive.event(input.delete_selected_rows)\nasync def delete_selected_rows():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.delete_selected_rows()\n\n\n@reactive.Effect\n@reactive.event(input.undo)\nasync def undo():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.undo()\n\n\n@reactive.Effect\n@reactive.event(input.redo)\nasync def redo():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.redo()\n\n\n@reactive.Effect\n@reactive.event(input.trigger_get_data)\nasync def trigger_get_data():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_get_data()\n\n\n@reactive.Effect\n@reactive.event(input.tabulator_data)\ndef tabulator_data():\n    print(input.tabulator_data()[0])\n
    "},{"location":"table/","title":"Table","text":"

    The table configuration is set with TableOptions:

    from pytabulator import TableOptions\n\ntable_options = TableOptions(\n    layout=\"fitData\",\n    height=\"600px\",\n    pagination=True,\n    selectable=True\n)\n

    The table options can either be passed to the render decorator:

    from pandas import read_csv\nfrom pytabulator import render_data_frame, TableOptions\n\ndf = read_csv(\"titanic.csv\")\n\ntable_options = TableOptions(\n    height=\"600px\",\n    pagination=True\n)\n\n@render_data_frame(table_options=table_options)\ndef tabulator():\n    return df\n

    Or to the Tablulator object:

    from pandas import read_csv\nfrom pytabulator import render_tabulator, TableOptions, Tabulator\n\ndf = read_csv(\"titanic.csv\")\n\ntable_options = TableOptions(\n    height=\"600px\",\n    pagination=True\n)\n\n@render_tabulator\ndef tabulator():\n    return Tabulator(df, table_options=table_options)\n
    "},{"location":"concept/themes/","title":"Themes","text":"

    See Tabulator JS Themes for details.

    Pytabulator comes with a number of pre-packaged theme stylesheets to make styling your table really simple. To use one of these instead of the default theme simply include the matching function before you render the table:

    from pytabulator import theme\n\ntheme.tabulator_midnight()\n
    "},{"location":"concept/themes/#standard-themes","title":"Standard themes","text":""},{"location":"concept/themes/#pytabulator.theme.tabulator_midnight","title":"tabulator_midnight()","text":"

    Midnight

    A dark, stylish layout using simple shades of grey.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_modern","title":"tabulator_modern()","text":"

    Modern

    A neat, stylish layout using one primary color.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_simple","title":"tabulator_simple()","text":"

    Simple

    A plain, simplistic layout showing only basic grid lines.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_site","title":"tabulator_site()","text":"

    Site

    The theme used for tables on the docs website of Tabulator JS.

    "},{"location":"concept/themes/#framework-themes","title":"Framework themes","text":""},{"location":"concept/themes/#pytabulator.theme.tabulator_bootstrap3","title":"tabulator_bootstrap3()","text":"

    Bootstrap 3

    A Bootstrap 3 compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_bootstrap4","title":"tabulator_bootstrap4()","text":"

    Bootstrap 4

    A Bootstrap 4 compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_bootstrap5","title":"tabulator_bootstrap5()","text":"

    Bootstrap 5

    A Bootstrap 5 compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_semanticui","title":"tabulator_semanticui()","text":"

    Semantic UI

    A Semantic UI compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_bulma","title":"tabulator_bulma()","text":"

    Bulma

    A Bulma compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_materialize","title":"tabulator_materialize()","text":"

    Materialize

    A Materialize compatible theme.

    "},{"location":"examples/exports/","title":"Downloads","text":"
    import pandas as pd\nfrom pytabulator import (\n    TableOptions,\n    Tabulator,\n    TabulatorContext,\n    render_tabulator,\n    theme,\n)\nfrom pytabulator.ui import use_sheetjs\nfrom shiny import reactive\nfrom shiny.express import input, ui\n\n# Include sheetjs to support xlsx downloads\n#\nuse_sheetjs()\n\nwith ui.div(style=\"padding-top: 10px;\"):\n    ui.input_action_button(\"trigger_download\", \"Download\")\n\nwith ui.div(style=\"padding-top: 10px;\"):\n    ui.input_select(\"data_type\", label=\"Data type\", choices=[\"csv\", \"json\", \"xlsx\"])\n\n\ntheme.tabulator_site()\n\n\n@render_tabulator\ndef tabulator():\n    df = pd.read_csv(\n        \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n    )\n    return Tabulator(\n        df,\n        TableOptions(\n            height=600,\n            pagination=True,\n            layout=\"fitColumns\",\n        ),\n    )\n\n\n@reactive.Effect\n@reactive.event(input.trigger_download)\nasync def trigger_download():\n    print(\"download triggered\")\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_download(input.data_type())\n
    "},{"location":"examples/themes/","title":"Themes","text":"
    import pandas as pd\nfrom pytabulator import TableOptions, Tabulator, render_tabulator, theme\nfrom shiny import render\nfrom shiny.express import input, ui\n\ntable_options = TableOptions(\n    height=600,\n    pagination=True,\n    layout=\"fitColumns\",\n)\n\n# Set theme\n#\ntheme.tabulator_midnight()\n\nui.div(\"Click on row to print name.\", style=\"padding: 10px;\")\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\n@render_tabulator\ndef tabulator():\n    df = pd.read_csv(\n        \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n    )\n    return Tabulator(df, table_options)\n
    "}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Welcome to Tabulator for Python","text":"

    Tabulator for Python provides Shiny for Python bindings for Tabulator JS.

    "},{"location":"#installation","title":"Installation","text":"
    # Stable\npip install pytabulator\n\n# Dev\npip install git+https://github.com/eodaGmbH/py-tabulator\n
    "},{"location":"#basic-usage","title":"Basic usage","text":"

    Shiny Express:

    import pandas as pd\nfrom pytabulator import TableOptions, render_data_frame\nfrom shiny import render\nfrom shiny.express import input, ui\n\nui.div(\"Click on row to print name\", style=\"padding: 10px;\")\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\n@render_data_frame(table_options=TableOptions(height=500))\ndef tabulator():\n    return pd.read_csv(\n        \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n    )\n

    Shiny core:

    import pandas as pd\nfrom pytabulator import TableOptions, Tabulator, output_tabulator, render_tabulator\nfrom shiny import App, render, ui\n\napp_ui = ui.page_fluid(\n    ui.output_text_verbatim(\"txt\", placeholder=True),\n    output_tabulator(\"tabulator\"),\n)\n\n\ndef server(input, output, session):\n    @render_tabulator\n    def tabulator():\n        df = pd.read_csv(\n            \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n        )\n        return Tabulator(df, table_options=TableOptions(height=311))\n\n    @render.code\n    async def txt():\n        print(input.tabulator_row_clicked())\n        return str(input.tabulator_row_clicked())\n\n\napp = App(app_ui, server)\n
    "},{"location":"api/","title":"API Documentation","text":""},{"location":"api/#basic-usage","title":"Basic usage","text":"
    import pandas as pd\nfrom pytabulator import TableOptions, render_data_frame\nfrom shiny import render\nfrom shiny.express import input, ui\n\nui.div(\"Click on row to print name\", style=\"padding: 10px;\")\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\n@render_data_frame(table_options=TableOptions(height=500))\ndef tabulator():\n    return pd.read_csv(\n        \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n    )\n

    See also detailed example.

    "},{"location":"api/#pytabulator.shiny_bindings","title":"pytabulator.shiny_bindings","text":""},{"location":"api/#pytabulator.shiny_bindings.render_data_frame","title":"render_data_frame","text":"

    Bases: Renderer[DataFrame]

    A decorator for a function that returns a DataFrame

    Parameters:

    Name Type Description Default table_options TableOptions

    Table options.

    {} Source code in pytabulator/shiny_bindings.py
    class render_data_frame(Renderer[DataFrame]):\n    \"\"\"A decorator for a function that returns a `DataFrame`\n\n    Args:\n        table_options (TableOptions): Table options.\n    \"\"\"\n\n    def auto_output_ui(self) -> Tag:\n        return output_tabulator(self.output_id)\n\n    def __init__(\n        self,\n        _fn: ValueFn[DataFrame] = None,\n        *,\n        table_options: TableOptions | dict = {},\n    ) -> None:\n        super().__init__(_fn)\n        self.table_options = table_options\n\n    async def render(self) -> Jsonifiable:\n        df = await self.fn()\n        # return {\"values\": value.values.tolist(), \"columns\": value.columns.tolist()}\n        # TODO: convert with js\n        data = df_to_dict(df)\n        data[\"options\"] = jsonifiable_table_options(self.table_options)\n        return data\n
    "},{"location":"api/#pytabulator.shiny_bindings.render_tabulator","title":"render_tabulator","text":"

    Bases: Renderer[Tabulator]

    A decorator for a function that returns a Tabulator table

    Source code in pytabulator/shiny_bindings.py
    class render_tabulator(Renderer[Tabulator]):\n    \"\"\"A decorator for a function that returns a `Tabulator` table\"\"\"\n\n    def auto_output_ui(self) -> Tag:\n        return output_tabulator(self.output_id)\n\n    async def transform(self, value: Tabulator) -> Jsonifiable:\n        # return {\"values\": value.values.tolist(), \"columns\": value.columns.tolist()}\n        # TODO: convert with js\n        return value.to_dict()\n
    "},{"location":"api/#pytabulator.shiny_bindings.output_tabulator","title":"output_tabulator(id)","text":"

    Create an output container for a Tabulator table

    Parameters:

    Name Type Description Default id str

    An output id of a Tabulator table.

    required Source code in pytabulator/shiny_bindings.py
    def output_tabulator(id: str):\n    \"\"\"Create an output container for a `Tabulator` table\n\n    Args:\n        id (str): An output id of a `Tabulator` table.\n    \"\"\"\n    return ui.div(\n        tabulator_dep(),\n        tabulator_bindings_dep,\n        id=resolve_id(id),\n        class_=\"shiny-tabulator-output\",\n    )\n
    "},{"location":"api/#pytabulator.utils","title":"pytabulator.utils","text":""},{"location":"api/#pytabulator.utils.create_columns","title":"create_columns(df, default_filter=False, default_editor=False, updates={})","text":"

    Create columns configuration from a data frame

    Parameters:

    Name Type Description Default df DataFrame

    The data frame to create columns from.

    required default_filter bool

    Whether to add a default header filter to each column.

    False default_editor bool

    Whether to add a default editor to each column.

    False updates dict

    Dictionary of updates that overwrite the default settings or add additional settings the columns.

    {} Source code in pytabulator/utils.py
    def create_columns(\n    df: DataFrame,\n    default_filter: bool = False,\n    default_editor: bool = False,\n    updates: dict = {},\n) -> list:\n    \"\"\"Create columns configuration from a data frame\n\n    Args:\n        df (DataFrame): The data frame to create columns from.\n        default_filter (bool): Whether to add a default header filter to each column.\n        default_editor (bool): Whether to add a default editor to each column.\n        updates (dict): Dictionary of updates that overwrite the default settings or add additional settings the columns.\n    \"\"\"\n    # (hozAlign, headerFilter, editor)\n    setup = [\n        (\n            (\"right\", \"number\", \"number\")\n            if dtype in [int, float]\n            else (\"left\", \"input\", \"input\")\n        )\n        for dtype in df.dtypes.tolist()\n    ]\n    columns = [\n        {\"title\": column, \"field\": column, \"hozAlign\": setup[i][0]}\n        for i, column in enumerate(df.columns)\n    ]\n\n    if default_filter:\n        for i, column in enumerate(columns):\n            column[\"headerFilter\"] = setup[i][1]\n\n    if default_editor:\n        for i, column in enumerate(columns):\n            column[\"editor\"] = setup[i][2]\n\n    for key in updates:\n        for column in columns:\n            if column[\"field\"] == key:\n                column.update(updates[key])\n\n    return columns\n
    "},{"location":"api/#pytabulator.tabulator","title":"pytabulator.tabulator","text":""},{"location":"api/#pytabulator.tabulator.Tabulator","title":"Tabulator","text":"

    Bases: object

    Tabulator

    Parameters:

    Name Type Description Default df DataFrame

    A data frame.

    required table_options TableOptions

    Table options.

    {} Source code in pytabulator/tabulator.py
    class Tabulator(object):\n    \"\"\"Tabulator\n\n    Args:\n        df (DataFrame): A data frame.\n        table_options (TableOptions): Table options.\n    \"\"\"\n\n    def __init__(\n        self,\n        df: DataFrame,\n        table_options: TableOptions | dict = {},\n    ) -> None:\n        self.df = df\n        self.table_options = table_options\n\n    def to_dict(self) -> dict:\n        data = df_to_dict(self.df)\n        data[\"options\"] = jsonifiable_table_options(self.table_options)\n        return data\n
    "},{"location":"api/#pytabulator.tabulator_context","title":"pytabulator.tabulator_context","text":""},{"location":"api/#pytabulator.tabulator_context.TabulatorContext","title":"TabulatorContext","text":"

    Bases: object

    Table context

    Source code in pytabulator/tabulator_context.py
    class TabulatorContext(object):\n    \"\"\"Table context\"\"\"\n\n    def __init__(self, id: str, session: Session = None) -> None:\n        self.id = id\n        self._session = require_active_session(session)\n        self._message_queue = []\n\n    async def __aenter__(self):\n        return self\n\n    async def __aexit__(self, exc_type, exc_val, exc_tb):\n        await self.render()\n\n    async def render(self):\n        await self._session.send_custom_message(\n            f\"tabulator-{self.id}\", {\"id\": self.id, \"calls\": self._message_queue}\n        )\n\n    def add_call(self, method_name: str, *args) -> None:\n        \"\"\"Add a method call that is executed on the table instance\n\n        Args:\n            method_name (str): The name of the method to be executed.\n            *args (any): The arguments to be passed to the table method.\n        \"\"\"\n        call = [method_name, args]\n        self._message_queue.append(call)\n\n    def trigger_download(\n        self, type: Literal[\"csv\", \"json\"] = \"csv\", file_name: str = None\n    ) -> None:\n        \"\"\"Trigger download\n\n        Args:\n            type (str): The data type of file to be downloaded.\n            file_name (str): The file name.\n        \"\"\"\n        if not file_name:\n            file_name = f\"tabulator-data.{type}\"\n\n        self.add_call(\"download\", type, file_name)\n\n    def add_row(self, row: dict = {}) -> None:\n        \"\"\"Add a row to the table\n\n        Args:\n            row (dict): Row data to add.\n        \"\"\"\n        self.add_call(\"addRow\", row)\n\n    def delete_row(self, index: int | str) -> None:\n        \"\"\"Delete a row from the table\n\n        Args:\n            index: The index of the row to delete.\n        \"\"\"\n        self.add_call(\"deleteRow\", index)\n\n    def delete_selected_rows(self) -> None:\n        \"\"\"Delete selected rows from table\"\"\"\n        self.add_call(\"deleteSelectedRows\")\n\n    def undo(self) -> None:\n        \"\"\"Trigger undo\"\"\"\n        self.add_call(\"undo\")\n\n    def redo(self) -> None:\n        \"\"\"Trigger redo\"\"\"\n        self.add_call(\"redo\")\n\n    def trigger_get_data(self) -> None:\n        \"\"\"Trigger sending data\"\"\"\n        self.add_call(\"getData\")\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.add_call","title":"add_call(method_name, *args)","text":"

    Add a method call that is executed on the table instance

    Parameters:

    Name Type Description Default method_name str

    The name of the method to be executed.

    required *args any

    The arguments to be passed to the table method.

    () Source code in pytabulator/tabulator_context.py
    def add_call(self, method_name: str, *args) -> None:\n    \"\"\"Add a method call that is executed on the table instance\n\n    Args:\n        method_name (str): The name of the method to be executed.\n        *args (any): The arguments to be passed to the table method.\n    \"\"\"\n    call = [method_name, args]\n    self._message_queue.append(call)\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.add_row","title":"add_row(row={})","text":"

    Add a row to the table

    Parameters:

    Name Type Description Default row dict

    Row data to add.

    {} Source code in pytabulator/tabulator_context.py
    def add_row(self, row: dict = {}) -> None:\n    \"\"\"Add a row to the table\n\n    Args:\n        row (dict): Row data to add.\n    \"\"\"\n    self.add_call(\"addRow\", row)\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.delete_row","title":"delete_row(index)","text":"

    Delete a row from the table

    Parameters:

    Name Type Description Default index int | str

    The index of the row to delete.

    required Source code in pytabulator/tabulator_context.py
    def delete_row(self, index: int | str) -> None:\n    \"\"\"Delete a row from the table\n\n    Args:\n        index: The index of the row to delete.\n    \"\"\"\n    self.add_call(\"deleteRow\", index)\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.delete_selected_rows","title":"delete_selected_rows()","text":"

    Delete selected rows from table

    Source code in pytabulator/tabulator_context.py
    def delete_selected_rows(self) -> None:\n    \"\"\"Delete selected rows from table\"\"\"\n    self.add_call(\"deleteSelectedRows\")\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.redo","title":"redo()","text":"

    Trigger redo

    Source code in pytabulator/tabulator_context.py
    def redo(self) -> None:\n    \"\"\"Trigger redo\"\"\"\n    self.add_call(\"redo\")\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.trigger_download","title":"trigger_download(type='csv', file_name=None)","text":"

    Trigger download

    Parameters:

    Name Type Description Default type str

    The data type of file to be downloaded.

    'csv' file_name str

    The file name.

    None Source code in pytabulator/tabulator_context.py
    def trigger_download(\n    self, type: Literal[\"csv\", \"json\"] = \"csv\", file_name: str = None\n) -> None:\n    \"\"\"Trigger download\n\n    Args:\n        type (str): The data type of file to be downloaded.\n        file_name (str): The file name.\n    \"\"\"\n    if not file_name:\n        file_name = f\"tabulator-data.{type}\"\n\n    self.add_call(\"download\", type, file_name)\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.trigger_get_data","title":"trigger_get_data()","text":"

    Trigger sending data

    Source code in pytabulator/tabulator_context.py
    def trigger_get_data(self) -> None:\n    \"\"\"Trigger sending data\"\"\"\n    self.add_call(\"getData\")\n
    "},{"location":"api/#pytabulator.tabulator_context.TabulatorContext.undo","title":"undo()","text":"

    Trigger undo

    Source code in pytabulator/tabulator_context.py
    def undo(self) -> None:\n    \"\"\"Trigger undo\"\"\"\n    self.add_call(\"undo\")\n
    "},{"location":"api/#pytabulator.TableOptions","title":"pytabulator.TableOptions dataclass","text":"

    Bases: TableOptions

    Table options

    Attributes:

    Name Type Description add_row_pos Literal['bottom', 'top']

    Where to add rows. Defaults to \"bottom\".

    columns list

    Column definitions.

    frozen_rows int

    Number of frozen rows. Defaults to \u01f8one.

    group_by Union[str, list]

    Columns to group by. Defaults to None.

    header_visible bool

    Whether to display the header of the table. Defaults to True.

    height Union[int, None]

    The height of the table in pixels. Defaults to 311.

    history bool

    Whether to enable history. Must be set if undo and redo is used. Defaults to False.

    index str

    The field to be used as a unique index for each row. Defaults to \"id\".

    layout Literal['fitData', 'fitDataFill', 'fitDataStretch', 'fitDataTable', 'fitColumns']

    The layout of the table. Defaults to \"fitColumns\".

    movable_rows bool

    Whether rows are movable. Defaults to False.

    pagination_add_row Literal['page', 'table']

    Where to add rows when pagination is enabled. Defaults to \"page\".

    pagination bool

    Whether to enable pagination. Defaults to False.

    pagination_counter str

    Whether to display counted rows in footer. Defaults to \"rows\".

    resizable_column_fit bool

    Maintain total column width when resizing a column. Defaults to False.

    row_height int

    Fixed height for rows. Defaults to None.

    selectable Union[str, bool, int]

    Whether a row is selectable. An integer value sets the maximum number of rows, that can be selected. If set to \"highlight\", rows do not change their state when they are clicked. Defaults to \"highlight\".

    Source code in pytabulator/_table_options_dc.py
    @dataclass\nclass TableOptionsDC(TableOptions):\n    \"\"\"Table options\n\n    Attributes:\n        add_row_pos: Where to add rows. Defaults to `\"bottom\"`.\n        columns: Column definitions.\n        frozen_rows: Number of frozen rows. Defaults to `\u01f8one`.\n        group_by: Columns to group by. Defaults to `None`.\n        header_visible: Whether to display the header of the table. Defaults to `True`.\n        height: The height of the table in pixels. Defaults to `311`.\n        history: Whether to enable history. Must be set if `undo` and `redo` is used. Defaults to `False`.\n        index: The field to be used as a unique index for each row. Defaults to `\"id\"`.\n        layout: The layout of the table. Defaults to `\"fitColumns\"`.\n        movable_rows: Whether rows are movable. Defaults to `False`.\n        pagination_add_row: Where to add rows when pagination is enabled. Defaults to `\"page\"`.\n        pagination: Whether to enable pagination. Defaults to `False`.\n        pagination_counter: Whether to display counted rows in footer. Defaults to `\"rows\"`.\n        resizable_column_fit: Maintain total column width when resizing a column. Defaults to `False`.\n        row_height: Fixed height for rows. Defaults to `None`.\n        selectable: Whether a row is selectable. An integer value sets the maximum number of rows, that can be selected.\n            If set to `\"highlight\"`, rows do not change their state when they are clicked. Defaults to `\"highlight\"`.\n    \"\"\"\n\n    add_row_pos: Literal[\"bottom\", \"top\"] = \"bottom\"\n    columns: list = None\n    frozen_rows: int = None\n    group_by: Union[str, list] = None\n    header_visible: bool = True\n    height: Union[int, None] = 311\n    history: bool = False\n    index: str = \"id\"\n    layout: Literal[\n        \"fitData\", \"fitDataFill\", \"fitDataStretch\", \"fitDataTable\", \"fitColumns\"\n    ] = \"fitColumns\"\n    movable_rows: bool = False\n    pagination_add_row: Literal[\"page\", \"table\"] = \"page\"\n    pagination: bool = False\n    pagination_counter: str = \"rows\"\n    resizable_column_fit: bool = False\n    row_height: int = None\n    selectable: Union[str, bool, int] = \"highlight\"\n\n    def to_dict(self):\n        return asdict(\n            self,\n            dict_factory=lambda x: {\n                snake_to_camel_case(k): v for (k, v) in x if v is not None\n            },\n        )\n
    "},{"location":"changelog/","title":"Changelog for Tabulator for Python","text":""},{"location":"changelog/#pytabulator-v023","title":"pytabulator v0.2.3","text":"
    • Make Pydantic optional
    "},{"location":"changelog/#pytabulator-v022-2024-02-04","title":"pytabulator v0.2.2 (2024-02-04)","text":"
    • Add themes
    • Add optional support for xlsx exports via sheetjs
    "},{"location":"changelog/#pytabulator-v021-2024-02-03","title":"pytabulator v0.2.1 (2024-02-03)","text":"
    • Set version of pandas requirement to >=1.5.3
    • Allow extra arguments in TableOptions
    "},{"location":"changelog/#pytabulator-v020-2024-02-02","title":"pytabulator v0.2.0 (2024-02-02)","text":"

    Initial PyPI release

    • Add docs
    • Rename TabulatorOptions to TableOptions
    • Use Pydantic for TableOptions
    • Add more input events
    • Add detailed example
    • Add utility function to create columns configuration from data frame
    "},{"location":"changelog/#pytabulator-v010-2024-01-31-pre-release","title":"pytabulator v0.1.0 (2024-01-31, Pre-release)","text":"

    Initial release

    "},{"location":"columns/","title":"Columns and filters","text":"

    With the columns argument of TableOptions you can configure the columns of the table.

    See Tabulator JS columns docs for a complete list of available setup options.

    "},{"location":"columns/#default-definition","title":"Default definition","text":"

    If no columns arguments is provided, title and field is set to the column name of the data frame. Furthermore, the alignment is set to right for numeric columns.

    from pandas import DataFrame\nfrom pytabulator import render_data_frame\n\ndata = [[\"Peter\", 10], [\"Hans\", 12]]\ndf = DataFrame(data, columns=[\"Name\", \"Age\"])\n\n@render_data_frame\ndef tabulator():\n    return df\n

    The following definition is created by default for the above data frame:

    columns = [\n    {\"title\": \"Name\", \"field\": \"Name\", \"horizAlign\": \"left\"},\n    {\"title\": \"Age\", \"field\": \"Age\", \"horizAlign\": \"right\"}\n]\n
    "},{"location":"columns/#customize-default-configuration","title":"Customize default configuration","text":"

    With create_columns you can customize the default configuration:

    from pandas import DataFrame\nfrom pytabulator import TableOptions\nfrom pytabulator.utils import create_columns\n\ndata = [[\"Peter\", 10, 102.5], [\"Hans\", 12, 200.9]]\ndf = DataFrame(data, columns=[\"Name\", \"Age\", \"JustANumber\"])\n\ntable_options = TableOptions(\n    columns=create_columns(\n        df,\n        default_filter=True,\n        default_editor=True,\n        updates={\"JustANumber\": {\"formatter\": \"progress\", \"horizAlign\": \"left\"}})\n)\n

    In the example above with default_editor=True all columns are set to editable and with default_filter=True a header filter is added to all columns. For numeric columns the editor and filter mode is set to number.

    The updates arguments allows you to overwrite any defaults set for a column. In this case the formatter of the numeric column JustANumber is set to progress and the alignment is changed from right to left.

    "},{"location":"columns/#calculations","title":"Calculations","text":"

    Calculations can be set with the bottomCalc parameter:

    from pytabulator import TableOptions\n\ncolumns = [\n    {\"title\": \"Name\", \"field\": \"Name\", \"horizAlign\": \"left\"},\n    {\"title\": \"Age\", \"field\": \"Age\", \"horizAlign\": \"right\", \"bottomCalc\": \"avg\"}\n]\n\ntable_options = TableOptions(columns=columns)\n
    "},{"location":"columns/#filters","title":"Filters","text":"

    You can add a filter to the columns with the headerFilter parameter:

    from pytabulator import TableOptions\n\ncolumns = [\n    {\n        \"title\": \"Name\",\n        \"field\": \"Name\",\n        \"horizAlign\": \"left\",\n        \"headerFilter\": True\n    },\n    {\n        \"title\": \"Age\",\n        \"field\": \"Age\",\n        \"horizAlign\": \"right\",\n        \"bottomCalc\": \"avg\",\n        \"headerFilter\": \"number\"\n    }\n]\n\ntable_options = TableOptions(columns=columns)\n

    Shiny Express example:

    import pandas as pd\nfrom pytabulator import TableOptions, Tabulator, TabulatorContext, render_tabulator\nfrom shiny import reactive, render\nfrom shiny.express import input, ui\n\ndf = pd.read_csv(\n    \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n)\n\n# Setup\n#\ncolumns = [\n    {\n        \"title\": \"Name\",\n        \"field\": \"Name\",\n        \"headerFilter\": True,\n        \"headerFilterPlaceholder\": \"Find a Person...\",\n        # \"headerFilterLiveFilter\": False,\n    },\n    {\n        \"title\": \"Survived\",\n        \"field\": \"Survived\",\n        \"hozAlign\": \"right\",\n        \"headerFilter\": \"list\",\n        \"headerFilterParams\": {\n            \"values\": {\n                \"1\": \"Survived\",\n                \"0\": \"Died\",\n            }\n        },\n    },\n]\n\ntable_options = TableOptions(\n    height=600, pagination=True, layout=\"fitDataTable\", columns=columns\n)\n\n# Shiny Express app\n#\nui.div(\n    ui.input_action_button(\"clear_filter\", \"Clear Filter\"),\n    style=\"padding-bottom: 10px; padding-top: 10px;\",\n)\n\n\n@reactive.Effect\n@reactive.event(input.clear_filter)\nasync def clear_filter():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.add_call(\"clearHeaderFilter\")\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_data_filtered())\n    return f\"Number of search result: {len(input.tabulator_data_filtered())}\"\n\n\n@render_tabulator\ndef tabulator():\n    return Tabulator(df, table_options)\n
    "},{"location":"columns/#editor","title":"Editor","text":"

    Set editor to True, \"input\" or \"number\" to make the cells of a column editable:

    columns = [\n    {\"title\": \"Name\", \"field\": \"Name\", \"horizAlign\": \"left\", \"editor\": True},\n    {\"title\": \"Age\", \"field\": \"Age\", \"horizAlign\": \"right\", \"editor\": \"number\"}\n]\n
    "},{"location":"events/","title":"Events and triggers","text":""},{"location":"events/#events","title":"Events","text":"

    Tabulator for Python provides the following reactive inputs:

    • input.{output_id}_row_clicked event: Sends the data of the clicked row.
    • input.{output_id}_row_edited event: Sends the data of the edited row. This event is fired each time a cell of the row is edited.
    • input.{output_id}_rows_selected event: Sends the data of all selected rows. This event is fired each time a new row is selected.
    • input.{output_id}_data event: Sends the complete data of the table. This event must be triggered from Shiny.
    • input.{output_id}_data_filtered event: Sends data of filtered rows. This event is triggered each time a filter is applied.
    from shiny import render\nfrom pandas import read_csv\nfrom pytabulator import render_data_frame\n\n\n# in this case (Shiny Express) the function name corresponds to the 'output_id'\n# output_id = \"tabulator\"\n#\n# on-row-clicked event: input.tabulator_row_clicked\n# on-row-edited event: input.tabulator_row_edited\n#\n@render_data_frame\ndef tabulator():\n    return read_csv(\"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\")\n\n\n# row-on-click event\n#\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\n# row-edited event\n#\n@render.code\ndef row_edited():\n    data = input.tabulator_row_edited()\n    print(data)\n    return f\"{data['Name']}, {data['Sex']}\"\n
    "},{"location":"events/#triggers","title":"Triggers","text":"

    With TabulatorContext you can trigger events on the table object. TabulatorContext must be used in an async function:

    from shiny import reactive\nfrom shiny.express import ui\nfrom pytabulator import TabulatorContext\n\nui.input_action_button(\"trigger_download\", \"Download\")\nui.input_action_button(\"add_row\", \"Add row\")\n\n\n# Trigger download of csv file\n#\n@reactive.Effect\n@reactive.event(input.trigger_download)\nasync def trigger_download():\n    print(\"download triggered\")\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_download(\"csv\")\n\n\n# Add a row to the table\n#\n@reactive.Effect\n@reactive.event(input.add_row)\nasync def add_row():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.add_row({\"Name\": \"Hans\", \"Sex\": \"male\"})\n
    "},{"location":"events/#detailed-example","title":"Detailed example","text":"
    from random import randrange\n\nimport pandas as pd\nfrom pytabulator import TableOptions, Tabulator, TabulatorContext, render_tabulator\nfrom pytabulator.utils import create_columns\nfrom shiny import reactive, render\nfrom shiny.express import input, ui\n\n# Fetch data\n#\ndf = pd.read_csv(\n    \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n)[[\"PassengerId\", \"Name\", \"Pclass\", \"Sex\", \"Age\", \"Fare\", \"Survived\"]]\n\n# Setup\n#\ntable_options = TableOptions(\n    columns=create_columns(\n        df,\n        default_filter=True,\n        default_editor=True,\n        updates={\n            \"Pclass\": {\n                \"formatter\": \"star\",\n                \"formatterParams\": {\"stars\": 3},\n                \"hozAlign\": \"center\",\n            },\n            \"Survived\": {\"formatter\": \"tickCross\"},\n            \"Fare\": {\"formatter\": \"progress\", \"hozAlign\": \"left\"},\n        },\n    ),\n    height=413,\n    pagination=True,\n    pagination_add_row=\"table\",\n    layout=\"fitColumns\",\n    index=\"PassengerId\",\n    add_row_pos=\"top\",\n    selectable=True,\n    history=True,\n)\n\n# Shiny Express App\n#\nwith ui.div(style=\"padding-top: 0px;\"):\n    ui.input_action_button(\"trigger_download\", \"Download\")\n    ui.input_action_button(\"add_row\", \"Add row\")\n    ui.input_action_button(\"delete_selected_rows\", \"Delete selected rows\")\n    ui.input_action_button(\"undo\", \"Undo\")\n    ui.input_action_button(\"redo\", \"Redo\")\n    ui.input_action_button(\"trigger_get_data\", \"Submit data\")\n\nui.div(\n    ui.input_text(\"name\", \"Click on 'Add row' to add the Person to the table.\"),\n    style=\"padding-top: 20px;\",\n)\nui.div(\"Click on a row to print the name of the person.\", style=\"padding: 10px;\"),\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\nui.div(\n    \"Select multiple rows to print the names of the selected persons.\",\n    style=\"padding: 10px;\",\n),\n\n\n@render.code\ndef selected_rows():\n    data = input.tabulator_rows_selected()\n    output = [item[\"Name\"] for item in data]\n    return \"\\n\".join(output)\n\n\n@render_tabulator\ndef tabulator():\n    return Tabulator(df, table_options)\n\n\n@reactive.Effect\n@reactive.event(input.trigger_download)\nasync def trigger_download():\n    print(\"download triggered\")\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_download(\"csv\")\n\n\n@reactive.Effect\n@reactive.event(input.add_row)\nasync def add_row():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.add_row(\n            {\n                \"Name\": input.name() or \"Hans\",\n                \"Age\": randrange(55),\n                \"Survived\": randrange(2),\n                \"PassengerId\": randrange(10000, 20000, 1),\n                \"SibSp\": randrange(9),\n            }\n        )\n\n\n@reactive.Effect\n@reactive.event(input.delete_selected_rows)\nasync def delete_selected_rows():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.delete_selected_rows()\n\n\n@reactive.Effect\n@reactive.event(input.undo)\nasync def undo():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.undo()\n\n\n@reactive.Effect\n@reactive.event(input.redo)\nasync def redo():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.redo()\n\n\n@reactive.Effect\n@reactive.event(input.trigger_get_data)\nasync def trigger_get_data():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_get_data()\n\n\n@reactive.Effect\n@reactive.event(input.tabulator_data)\ndef tabulator_data():\n    print(input.tabulator_data()[0])\n
    "},{"location":"example/","title":"Showcase","text":"

    This example uses Shiny Express.

    shiny run docs/examples/getting_started/shiny_express_all.py\n
    from random import randrange\n\nimport pandas as pd\nfrom pytabulator import TableOptions, Tabulator, TabulatorContext, render_tabulator\nfrom pytabulator.utils import create_columns\nfrom shiny import reactive, render\nfrom shiny.express import input, ui\n\n# Fetch data\n#\ndf = pd.read_csv(\n    \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n)[[\"PassengerId\", \"Name\", \"Pclass\", \"Sex\", \"Age\", \"Fare\", \"Survived\"]]\n\n# Setup\n#\ntable_options = TableOptions(\n    columns=create_columns(\n        df,\n        default_filter=True,\n        default_editor=True,\n        updates={\n            \"Pclass\": {\n                \"formatter\": \"star\",\n                \"formatterParams\": {\"stars\": 3},\n                \"hozAlign\": \"center\",\n            },\n            \"Survived\": {\"formatter\": \"tickCross\"},\n            \"Fare\": {\"formatter\": \"progress\", \"hozAlign\": \"left\"},\n        },\n    ),\n    height=413,\n    pagination=True,\n    pagination_add_row=\"table\",\n    layout=\"fitColumns\",\n    index=\"PassengerId\",\n    add_row_pos=\"top\",\n    selectable=True,\n    history=True,\n)\n\n# Shiny Express App\n#\nwith ui.div(style=\"padding-top: 0px;\"):\n    ui.input_action_button(\"trigger_download\", \"Download\")\n    ui.input_action_button(\"add_row\", \"Add row\")\n    ui.input_action_button(\"delete_selected_rows\", \"Delete selected rows\")\n    ui.input_action_button(\"undo\", \"Undo\")\n    ui.input_action_button(\"redo\", \"Redo\")\n    ui.input_action_button(\"trigger_get_data\", \"Submit data\")\n\nui.div(\n    ui.input_text(\"name\", \"Click on 'Add row' to add the Person to the table.\"),\n    style=\"padding-top: 20px;\",\n)\nui.div(\"Click on a row to print the name of the person.\", style=\"padding: 10px;\"),\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\nui.div(\n    \"Select multiple rows to print the names of the selected persons.\",\n    style=\"padding: 10px;\",\n),\n\n\n@render.code\ndef selected_rows():\n    data = input.tabulator_rows_selected()\n    output = [item[\"Name\"] for item in data]\n    return \"\\n\".join(output)\n\n\n@render_tabulator\ndef tabulator():\n    return Tabulator(df, table_options)\n\n\n@reactive.Effect\n@reactive.event(input.trigger_download)\nasync def trigger_download():\n    print(\"download triggered\")\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_download(\"csv\")\n\n\n@reactive.Effect\n@reactive.event(input.add_row)\nasync def add_row():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.add_row(\n            {\n                \"Name\": input.name() or \"Hans\",\n                \"Age\": randrange(55),\n                \"Survived\": randrange(2),\n                \"PassengerId\": randrange(10000, 20000, 1),\n                \"SibSp\": randrange(9),\n            }\n        )\n\n\n@reactive.Effect\n@reactive.event(input.delete_selected_rows)\nasync def delete_selected_rows():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.delete_selected_rows()\n\n\n@reactive.Effect\n@reactive.event(input.undo)\nasync def undo():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.undo()\n\n\n@reactive.Effect\n@reactive.event(input.redo)\nasync def redo():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.redo()\n\n\n@reactive.Effect\n@reactive.event(input.trigger_get_data)\nasync def trigger_get_data():\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_get_data()\n\n\n@reactive.Effect\n@reactive.event(input.tabulator_data)\ndef tabulator_data():\n    print(input.tabulator_data()[0])\n
    "},{"location":"table/","title":"Table","text":"

    The table configuration is set with TableOptions:

    from pytabulator import TableOptions\n\ntable_options = TableOptions(\n    layout=\"fitData\",\n    height=\"600px\",\n    pagination=True,\n    selectable=True\n)\n

    The table options can either be passed to the render decorator:

    from pandas import read_csv\nfrom pytabulator import render_data_frame, TableOptions\n\ndf = read_csv(\"titanic.csv\")\n\ntable_options = TableOptions(\n    height=\"600px\",\n    pagination=True\n)\n\n@render_data_frame(table_options=table_options)\ndef tabulator():\n    return df\n

    Or to the Tablulator object:

    from pandas import read_csv\nfrom pytabulator import render_tabulator, TableOptions, Tabulator\n\ndf = read_csv(\"titanic.csv\")\n\ntable_options = TableOptions(\n    height=\"600px\",\n    pagination=True\n)\n\n@render_tabulator\ndef tabulator():\n    return Tabulator(df, table_options=table_options)\n
    "},{"location":"concept/themes/","title":"Themes","text":"

    See Tabulator JS Themes for details.

    Pytabulator comes with a number of pre-packaged theme stylesheets to make styling your table really simple. To use one of these instead of the default theme simply include the matching function before you render the table:

    from pytabulator import theme\n\ntheme.tabulator_midnight()\n
    "},{"location":"concept/themes/#standard-themes","title":"Standard themes","text":""},{"location":"concept/themes/#pytabulator.theme.tabulator_midnight","title":"tabulator_midnight()","text":"

    Midnight

    A dark, stylish layout using simple shades of grey.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_modern","title":"tabulator_modern()","text":"

    Modern

    A neat, stylish layout using one primary color.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_simple","title":"tabulator_simple()","text":"

    Simple

    A plain, simplistic layout showing only basic grid lines.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_site","title":"tabulator_site()","text":"

    Site

    The theme used for tables on the docs website of Tabulator JS.

    "},{"location":"concept/themes/#framework-themes","title":"Framework themes","text":""},{"location":"concept/themes/#pytabulator.theme.tabulator_bootstrap3","title":"tabulator_bootstrap3()","text":"

    Bootstrap 3

    A Bootstrap 3 compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_bootstrap4","title":"tabulator_bootstrap4()","text":"

    Bootstrap 4

    A Bootstrap 4 compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_bootstrap5","title":"tabulator_bootstrap5()","text":"

    Bootstrap 5

    A Bootstrap 5 compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_semanticui","title":"tabulator_semanticui()","text":"

    Semantic UI

    A Semantic UI compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_bulma","title":"tabulator_bulma()","text":"

    Bulma

    A Bulma compatible theme.

    "},{"location":"concept/themes/#pytabulator.theme.tabulator_materialize","title":"tabulator_materialize()","text":"

    Materialize

    A Materialize compatible theme.

    "},{"location":"examples/exports/","title":"Downloads","text":"
    import pandas as pd\nfrom pytabulator import (\n    TableOptions,\n    Tabulator,\n    TabulatorContext,\n    render_tabulator,\n    theme,\n)\nfrom pytabulator.ui import use_sheetjs\nfrom shiny import reactive\nfrom shiny.express import input, ui\n\n# Include sheetjs to support xlsx downloads\n#\nuse_sheetjs()\n\nwith ui.div(style=\"padding-top: 10px;\"):\n    ui.input_action_button(\"trigger_download\", \"Download\")\n\nwith ui.div(style=\"padding-top: 10px;\"):\n    ui.input_select(\"data_type\", label=\"Data type\", choices=[\"csv\", \"json\", \"xlsx\"])\n\n\ntheme.tabulator_site()\n\n\n@render_tabulator\ndef tabulator():\n    df = pd.read_csv(\n        \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n    )\n    return Tabulator(\n        df,\n        TableOptions(\n            height=600,\n            pagination=True,\n            layout=\"fitColumns\",\n        ),\n    )\n\n\n@reactive.Effect\n@reactive.event(input.trigger_download)\nasync def trigger_download():\n    print(\"download triggered\")\n    async with TabulatorContext(\"tabulator\") as table:\n        table.trigger_download(input.data_type())\n
    "},{"location":"examples/themes/","title":"Themes","text":"
    import pandas as pd\nfrom pytabulator import TableOptions, Tabulator, render_tabulator, theme\nfrom shiny import render\nfrom shiny.express import input, ui\n\ntable_options = TableOptions(\n    height=600,\n    pagination=True,\n    layout=\"fitColumns\",\n)\n\n# Set theme\n#\ntheme.tabulator_midnight()\n\nui.div(\"Click on row to print name.\", style=\"padding: 10px;\")\n\n\n@render.code\nasync def txt():\n    print(input.tabulator_row_clicked())\n    return input.tabulator_row_clicked()[\"Name\"]\n\n\n@render_tabulator\ndef tabulator():\n    df = pd.read_csv(\n        \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\"\n    )\n    return Tabulator(df, table_options)\n
    "}]} \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 7e03dbb..3eb0410 100644 Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ diff --git a/table/index.html b/table/index.html index bcc894e..6b3b7e0 100644 --- a/table/index.html +++ b/table/index.html @@ -223,7 +223,7 @@
  • - + Examples @@ -601,6 +601,27 @@ +
  • + + + + + Showcase + + + + +
  • + + + + + + + + + +