Introduction
ClassicTable
is a widget in Supervisely that is used for displaying and manipulating data in a table format. It is similar to the Table
widget but with fewer customization options and functionalities.
Note, that this is a legacy version. It is recommended to use the newer Table
widget instead.
Function signature
Copy classic_table = ClassicTable ()
classic_table . read_pandas (pd. DataFrame (data = data, index = b, columns = a))
or
Copy classic_table = ClassicTable (
data = pd. DataFrame (data = data, index = b, columns = a),
fixed_columns_num = 1 ,
widget_id = None
)
Parameters
Parameters Type Description Number of fixed columns (left to right)
data
Data of table in different formats:
Copy pd . DataFrame (data = data, columns = columns)
Python dict with structure:
Copy {
"columns_names" : [ "col_name_1" , "col_name_2" , ...] ,
"values_by_rows" : [
[ "row_1_column_1" , "row_1_column_2" , ...] ,
[ "row_2_column_1" , "row_2_column_2" , ...] ,
...
]
}
# prepare data for table
a = list ( range ( 1 , 11 ))
b = list ( range ( 1 , 5 ))
data = []
for row in b :
temp = [ round (row * number, 1 ) for number in a]
data . append (temp)
a = [ str (i) for i in a]
b = [ str (i) for i in b]
data = pd . DataFrame (data = data, index = b, columns = a)
classic_table = ClassicTable (data = df) py
columns
List of columns names.
type: list
default value: None
Copy columns = [ f "Col# { i } " for i in range ( 1 , 11 ) ]
data = pd . DataFrame (data = data, index = b, columns = columns)
classic_table = ClassicTable (data = df)
fixed_columns_num
Number of fixed colums (left to right).
type: int
default value: None
Copy classic_table = ClassicTable (data = df, fixed_columns_num = 2 )
widget_id
ID of the widget.
type: str
default value: None
Methods and attributes
Attributes and Methods Description Get or set number of fixed columns (left to right) property.
Convert table data to json.
Convert table data to pandas dataframe.
Read and set table data from json.
read_pandas(value: pd.DataFrame)
Read and set table data from pandas dataframe.
pop_row(value: pd.DataFrame)
Remove row from table by index.
Get selected table cell info.
Mini App Example
You can find this example in our Github repository:
ui-widgets-demos/tables/002_classic_table/src/main.py
Import libraries
Copy import os
import pandas as pd
import supervisely as sly
from dotenv import load_dotenv
from supervisely . app . widgets import Card , ClassicTable , Container
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
Copy load_dotenv ( "local.env" )
load_dotenv (os.path. expanduser ( "~/supervisely.env" ))
api = sly . Api ()
Prepare function that creates example pandas table
Copy def multiplication_table ():
a = list ( range ( 1 , 11 ))
b = list ( range ( 1 , 6 ))
data = []
for row in b :
temp = [ round (row * number, 1 ) for number in a]
temp [ - 1 ] = sly . app . widgets . Table . create_button ( "Delete row" )
data . append (temp)
a = [ f "Col# {str (i) } " for i in a]
b = [ str (i) for i in b]
return pd . DataFrame (data = data, index = b, columns = a)
Create data for table.
Copy df = multiplication_table ()
Initialize ClassicTable
widget
Copy classic_table = ClassicTable (data = df)
or you can initialize empty table and set data later.
Copy classic_table = ClassicTable ()
classic_table . read_pandas (df)
Create 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.
Copy card = Card (
title = "Classic Table" ,
content = classic_table,
)
layout = Container (widgets = [card])
Create app using layout
Create an app object with layout parameter.
Copy app = sly . Application (layout = layout)