FastTable
Introduction
FastTable
widget in Supervisely allows for displaying and manipulating data of various dataset statistics and processing it on the server side.
The FastTable
widget allows searching, sorting by column and order, and the ability to customize data. It also allows updating table data in real-time through Python code.
😲 The main feature of FastTable
in that all information is processed on the server side and transmitted in the size of the active page of the table to the client, thus making its operation more efficient.
Function signature
Data structure example
Parameters
data
Optional[Union[list, pd.DataFrame]]
Table data
columns
Optional[list]
Table columns
columns_options
Optional[list[dict]]
Columns options
project_meta
Optional[Union[ProjectMeta, dict]]
Project metadata
fixed_columns
Optional[Literal[1]]
Number of the first fixed columns
page_size
Optional[int]
Table page size in number of rows
sort_column_idx
int
Index of the column by which sorting works
sort_order
Optional[Literal["asc", "desc"]]
Sort order
width
Optional[str]
Width of table
widget_id
Optional[str]
ID of the widget
data
Table data in different formats:
type: Optional[Union[list, pd.DataFrame]]
default value: None
Python
list
with structure:Where:
data_list
- list withrows
Pandas
DataFrame
:Where:
columns
- list of column namesdata
- list withrows
row
- list with values, requireslen(row) == len(columns)
columns
Column names.
💡 If data
in DataFrame
type is passed, specifying columns
will overwrite it in DataFrame
type: Optional[list]
default value: None
columns_options
List of dictionaries with column options. len(columns_options)
must equal len(columns)
to properly add options. If the column has no options, just pass an empty dictionary {}
Each dictionary may contain:
type
- with value of typestr
, determines special column type, depending on which styles will be applied, now supports onlyclass
as special type, you don't need to specify a type for the regular onessubtitle
- with value of typestr
, provide additional clarification, specify units of measurement, offer context, and enhance overall understanding of the datamaxValue
- with value of typeint
, determines the maximum value for the column and activates special bars that visualize how close the value is to the maximum valuepostfix
- with value of typestr
, is substituted after each value to denote dimensionalitytooltip
- with value of typestr
, tooltip with description for a column
type: Optional[list[dict]]
default value: None
project_meta
Project metadata with classes used to apply special styles for columns with type
:class
type: Optional[Union[ProjectMeta, dict]]
default value: None
fixed_columns
Number of the first fixed columns if the table has horizontal scrolling.
💡 Currently supports only 1
or None
as value.
type: Optional[Literal[1]]
default value: None
page_size
Table page size in number of rows
type: int
default value: 10
sort_column_idx
Index of the column by which sorting works.
💡 Cannot be used without sort_order
, if one of parameters is not set - the sorting will follow the original data structure.
type: int
default value: None
sort_order
Sort order.
💡 Cannot be used without sort_column_idx
, if one of parameters is not set - the sorting will follow the original data structure.
type: Optional[Literal["asc", "desc"]]
default value: None
width
Width of table.
type: Optional[str]
default value: auto
widget_id
ID of the widget.
type: str
default value: None
Methods and attributes
fixed_columns_num
Get or set number of fixed columns (left to right) property.
project_meta
Get or set number project meta property.
page_size
Get or set table page size property.
read_json(data: dict, meta: dict = None)
Read and set table data from JSON format.
read_pandas(data: pd.DataFrame)
Read and set table data from DataFrame
.
to_json(active_page = False)
Convert table data to JSON format. Full table or active page only.
to_pandas(active_page = False)
Convert table data to pandas DataFrame
. Full table or active page only.
clear_selection()
Deselect a table cell.
get_selected_row()
Get selected table row info.
get_selected_cell()
Get selected table cell info.
insert_row(row: List, index=-1)
Insert new row in table by index.
pop_row(index=-1)
Remove row from table by index.
search(search_value)
Search source data for search_value
and return results as DataFrame
.
sort(column_id: int, order: Optional[Literal["asc", "desc"]])
Sort table rows by given column ID and/or order direction.
@row_click
Decorator function is handled when table row is clicked.
@cell_click
Decorator function is handled when table cell is clicked.
read_json()
The data
structure must correspond to the dictionary given in the example below 👇
Structure:
columns
- list of column namesdata
- list withrows
row
- list with values, requireslen(row) == len(columns)
columnsOptions
- list of dictionaries in which settings for each column are storedtype
- determines special type of column, depending on which styles will be applied, now supports onlyclass
as special type, you don't need to specify a type for regularsubtitle
- provide additional clarification, specify units of measurement, offer context, and enhance overall understanding of the datamaxValue
- determines the maximum value for the column and activates special bars that visualize how close the value is to the maximum valuepostfix
- is substituted after each value to denote dimensionalitytooltip
- tooltip with description for a column
options
- dict with table optionsfixColumns
- number of first fixed table columns. ℹ️ Currently, only the first column is supportedsort
- dict with applied sorting optionscolumnIndex
- index of thecolumn
, by the values of which the data should be sortedorder
- sort order
pageSize
- how manyrows
will be displayed on the table page
Here is an example of the described structure: json_data_example
This data is under MIT license. Source
An example of a table built from this JSON can be seen on the datasets' page on Dataset Ninja.
Mini App Example
You can find this example in our Github repository:
ui-widgets-demos/tables/006_fast_table/src/main.py
Import libraries
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
Prepare data and meta that will be used to create example table
Initialize FastTable
widget
FastTable
widgetCreate app layout
Prepare a layout for app using Card
widget with the content
parameter and place widget that we've just created in the Container
widget.
Create app using layout
Create an app object with layout parameter.
Add functions to control widget from python code
Last updated