orangeqs.juice.dashboard.widgets.common.datatable_widget#

Base class for 2D data with named rows and columns. Uses pn.widgets.Tabulator.

Module Contents#

Classes#

DataTableWidget

Base class for 2D data with named rows and columns. Uses pn.widgets.Tabulator.

API#

class orangeqs.juice.dashboard.widgets.common.datatable_widget.DataTableWidget(column_names: list[str], column_display_names: dict[str, str] | None = None, row_names: list[str] | None = None, row_names_column_name: str | None = None, update_period: int = 1000, data_table_opts: dict[str, Any] | None = {}, tabulator_opts: dict[str, Any] | None = {}, initial_values: dict[str, Any] | None = {})#

Bases: param.Parameterized

Base class for 2D data with named rows and columns. Uses pn.widgets.Tabulator.

Parameters#

  • column_names (list[str]): The column names.

  • column_display_names (dict[str, str], optional): A mapping from column name to display name. Will be displayed as table header. If a column is not present, defaults to capitalized field name.

  • row_names (str, optional): The row names. If not provided, _set_row_names should be called later.

  • row_names_column_name (str, optional): The name of the column that displays the row names.

  • update_period (int, optional): Update period in milliseconds. Defaults to 1000ms.

  • tabulator_opts (dict[str, Any], optional): Standard Tabulator options exposed by Panel. See https://panel.holoviz.org/reference/widgets/Tabulator.html.

  • data_table_opts (dict[str, Any], optional): TabulatorJS configuration options. These are passed to the JS library and can be used to set configuration options that Panel does not expose. See https://www.tabulator.info/docs/6.3/options for available options.

  • initial_values (dict[str, Any], optional): Initial values for the table data.

Examples#

class MyTable(DataTableWidget):
    def __init_():
        super().__init__(
            column_names=["cpu_percent", "mem_percent", "mem_usage"],
            column_display_names={
                "cpu_percent": "CPU [%]",
                "mem_percent": "Memory [%]",
                "mem_usage": "Memory Usage",
            },
            data_table_opts=data_table_opts,
            initial_values={"mem_usage": pd.Series(dtype=str)},
        )

    @override
    async def _update(self) -> pd.DataFrame | None:
        return generate_dataframe()

my_table = MyTable()
panel.state.execute(my_table.start)

Here, initial_values is passed so the memory data will not be interpreted as a number and displayed as “NaN”. Furthermore, panel.state.execute is used to acquire the Bokeh document lock so the UI can be updated.

Note that overriding _update is necessary for the automatic update loop to work. If you do not want the widget to update automatically, you can simply not override _update and not call start.

table: panel.widgets.Tabulator#

None

async start() None#

Start the widget update loop.