Skip to content

Toggle#

Toggle #

Toggle(
    data: Union[DataType, DataFrame],
    *,
    id_column: str = "id",
    label: Union[str, WidgetField] = "",
    label_column: Optional[str] = None,
    widget_id: Optional[str] = None,
    default_selection: Optional[str] = None
)

Enables selection from list, toggling between entries/settings.

Enables users to select from a list of entries, providing a mechanism to toggle between different selections or settings.

Constructor for Toggle widget.

Parameters:

Name Type Description Default
id_column str

Column name in pandas DataFrame used as entries ids.

'id'
data Union[DataType, DataFrame]

data source for the widget.

required
label Union[str, WidgetField]

toggle widget label.

''
label_column Optional[str]

Column name in pandas DataFrame used for the widget labeling.

None
widget_id Optional[str]

unique widget id in a dashboard.

None
default_selection Optional[str]

pre selected entities on initial state.

None

Examples:#

Create a minimal Toggle widget
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.widgets import toggle

df = pd.DataFrame(
    {
        "id": ["1", "2", "3"],
    }
)
Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=toggle.Toggle(df),
)
Change the label for each entry
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.widgets import toggle

df = pd.DataFrame(
    {
        "id": ["1", "2", "3"],
        "label": ["First", "Second", "Third"],
    }
)
Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=toggle.Toggle(df, label_column="label"),
)