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.
{
"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
columns = [f"Col#{i}" for i in range(1, 11)]
data = pd.DataFrame(data=data, index=b, columns=columns)
classic_table = ClassicTable(data=df)
Get or set number of fixed columns (left to right) property.
to_json()
Convert table data to json.
to_pandas()
Convert table data to pandas dataframe.
read_json(value: dict)
Read and set table data from json.
read_pandas(value: pd.DataFrame)
Read and set table data from pandas dataframe.
insert_row(index=-1)
Insert new row in table.
pop_row(value: pd.DataFrame)
Remove row from table by index.
get_selected_cell(state)
Get selected table cell info.
Mini App Example
You can find this example in our Github repository:
Import libraries
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:
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()
Prepare function that creates example pandas table
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.
df = multiplication_table()
Initialize ClassicTable widget
classic_table = ClassicTable(data=df)
or you can initialize empty table and set data later.