Skip to content

Search#

Search #

Search(
    *,
    data: Union[DataType, DataFrame],
    selected_text_column: TemplatedStringItem,
    widget_id: Optional[str] = None,
    items: Optional[
        Union[TemplatedStringItem, List[ResultItemType]]
    ] = None,
    placeholder: Optional[TemplatedStringItem] = None
)

Construct search widget.

Construct a search widget for searching through data, allowing customization of selected text column, widget ID, search items, and placeholder text.

Constructor for Search widget.

Parameters:

Name Type Description Default
data Union[DataType, DataFrame]

data source for the widget.

required
selected_text_column TemplatedStringItem

Column with information to show when the option is selected.

required
widget_id Optional[str]

widget ID.

None
items Optional[Union[TemplatedStringItem, List[ResultItemType]]]

List of ResultItemTypes to be displayed in the search results.

None
placeholder Optional[TemplatedStringItem]

Default text to show before searching.

None

Examples:#

Create a minimal Search Widget
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.widgets import search

data = pd.DataFrame(
    data=[
        {"key": "AAPL", "name": "Apple"},
        {"key": "MSFT", "name": "Microsoft"},
    ]
)

# add_result_items allows info to be displayed in the drop-down list
# when searching for an item
search_widget = search.Search(
    data=data,
    selected_text_column="name",
)
Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=search_widget,
)

Items#

ResultTextItem #

ResultTextItem(
    data_column: TemplatedStringItem,
    searchable: bool = True,
    styling: Optional[
        Union[Palette, ResultTextStyling]
    ] = None,
)

Define text item for search results.

Define a text item for search results, specifying the data column to display, whether it's searchable, and styling options.

Constructor for ResultTextItem.

Parameters:

Name Type Description Default
data_column TemplatedStringItem

Column name in pandas DataFrame used for search result.

required
searchable bool

Flag that makes the result searchable.

True
styling Optional[Union[Palette, ResultTextStyling]]

Specs for Search Result styling.

None

ResultTextStyling #

ResultTextStyling(
    *,
    color_spec: Optional[ColorSpec] = None,
    data_column: Optional[TemplatedStringItem] = None
)

Style text search result columns.

Specify styling options for text search result columns, including color specifications and data column mapping.

Parameters:

Name Type Description Default
color_spec Optional[ColorSpec]

Spec for coloring columns.

None
data_column Optional[TemplatedStringItem]

Name of column in pandas dataframe(s) used for color spec if a gradient is used. Optional for single colors.

None

Construct for Search Widget Result Column Style.

Parameters:

Name Type Description Default
color_spec Optional[ColorSpec]

Spec for coloring columns.

None
data_column Optional[TemplatedStringItem]

Name of column in pandas dataframe(s) used for color spec if a gradient is used. Optional for single colors.

None

Examples:#

Changing the color of a text search result item
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.styling import color
from engineai.sdk.dashboard.widgets import search

data = pd.DataFrame(
    data=[
        {"key": "AAPL", "name": "Apple", "score": 10},
        {"key": "MSFT", "name": "Microsoft", "score": 5},
    ]
)

search_widget = search.Search(
    data=data,
    selected_text_column="name",
    items=[
        search.ResultTextItem(
            data_column="score",
            styling=search.ResultTextStyling(
                color_spec=color.Palette.ASHES_GREY,
            ),
        ),
    ],
)

Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=search_widget,
)

ResultNumberItem #

ResultNumberItem(
    data_column: TemplatedStringItem,
    formatting: Optional[NumberFormatting] = None,
    styling: Optional[
        Union[Palette, ResultNumberStyling]
    ] = None,
)

Define number item for search results.

Define a number item for search results, specifying the data column to display, formatting options, and styling options.

Constructor for ResultNumberItem.

Parameters:

Name Type Description Default
data_column TemplatedStringItem

Column name in pandas DataFrame used for search result.

required
formatting Optional[NumberFormatting]

formatting spec.

None
styling Optional[Union[Palette, ResultNumberStyling]]

Specs for Search Result styling.

None

Examples:#

Create a minimal search widget with a result number item
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.widgets import search

data = pd.DataFrame(
    data=[
        {"key": "AAPL", "name": "Apple", "score": 10},
        {"key": "MSFT", "name": "Microsoft", "score": 5},
    ]
)

search_widget = search.Search(
    data=data,
    items=[
        search.ResultTextItem(data_column="key"),
        search.ResultNumberItem(data_column="score"),
    ],
    selected_text_column="name",
)

Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=search_widget,
)

ResultNumberStyling #

ResultNumberStyling(
    *,
    color_spec: Optional[ColorSpec] = None,
    data_column: Optional[TemplatedStringItem] = None
)

Style number search result columns.

Specify styling options for number search result columns, including color specifications and data column mapping.

Construct for Search Widget Result Column Style.

Parameters:

Name Type Description Default
color_spec Optional[ColorSpec]

Spec for coloring columns.

None
data_column Optional[TemplatedStringItem]

Name of column in pandas dataframe(s) used for color spec if a gradient is used. Optional for single colors.

None

Examples:#

Changing the color of a number search result item
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.styling import color
from engineai.sdk.dashboard.widgets import search

data = pd.DataFrame(
    data=[
        {"key": "AAPL", "name": "Apple", "score": 10},
        {"key": "MSFT", "name": "Microsoft", "score": 5},
    ]
)

search_widget = search.Search(
    data=data,
    selected_text_column="name",
    items=[
        search.ResultTextItem(data_column="key"),
        search.ResultNumberItem(
            data_column="score",
            styling=search.ResultNumberStyling(
                color_spec=color.Palette.BABY_BLUE,
            ),
        ),
    ],
)

Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=search_widget,
)