Skip to content

selector

A control that allows for selecting items from a list of choices.

Each item is represented by a string, an image or both.

The selector can let the user select multiple items.

A filtering feature is available to display only a subset of the items.

You can use an arbitrary type for all the items (see the example).

Properties

Name Type Default Description
filter bool False

If True, this control is combined with a filter input area.

multiple bool False

If True, the user can select multiple items.

width str|int "360px"

The width, in CSS units, of this element.

height str|int

The height, in CSS units, of this element.

dropdown bool False

If True, the list of items is shown in a dropdown menu.
You cannot use the filter in that situation.

label str None

The label associated with the selector when in dropdown mode.

value(★) dynamic(Any)

Bound to the selection value.

lov dict[str, Any]

The list of values. See the section on List of Values for details.

adapter Function `lambda x: str(x)`

The function that transforms an element of lov into a tuple(id:str, label:str|Icon).

type str Type of first lov element

Must be specified if lov contains a non-specific type of data (ex: dict). value must be of that type, lov must be an iterable on this type, and the adapter function will receive an object of this type.

value_by_id bool False

If False, the selection value (in value) is the selected element in lov. If set to True, then value is set to the id of the selected element in lov.

propagate bool App config

Allows the control's main value to be automatically propagated.
The default value is defined at the application configuration level. If True, any change to the control's value is immediately reflected in the bound application variable.

(★)value is the default property for this visual element.

Usage

Display a list of string

You can create a selector on a series of strings:

Page content

<|{value}|selector|lov=Item 1;Item 2;Item 3|>
<taipy:selector lov="Item 1;Item 2;Item 3">{value}</taipy:selector>

Display as a dropdown

Page content

<|{value}|selector|lov=Item 1;Item 2;Item 3|dropdown|>
<taipy:selector lov="Item 1;Item 2;Item 3" dropdown="True">{value}</taipy:selector>

Display with filter and multiple selection

You can add a filter input field that lets you display only strings that match the filter value.

Page content

<|{value}|selector|lov=Item 1;Item 2;Item 3|multiple|filter|>
<taipy:selector lov="Item 1;Item 2;Item 3" multiple="True" filter="True">{value}</taipy:selector>

Display a list of tuples

A selector control that returns an id while selecting a label or Icon.

Page content

<|{sel}|selector|lov={[("id1", "Label 1"), ("id2", Icon("/images/icon.png", "Label 2"),("id3", "Label 3")]}|>
<taipy:selector value="{sel}" lov="{[('id1', 'Label 1'), ('id2', Icon('/images/icon.png', 'Label 2'),('id3', 'Label 3')]}" />

Display a list of objects

Assuming your Python code has created a list of object:

class User:
    def __init__(self, id, name, birth_year):
        self.id, self.name, self.birth_year = (id, name, birth_year)

users = [
    User(231, "Johanna", 1987),
    User(125, "John", 1979),
    User(4,   "Peter", 1968),
    User(31,  "Mary", 1974)
    ]

user_sel = users[2]

If you want to create a selector control that lets you pick a specific user, you can use the following fragment.

Page content

<|{user_sel}|selector|lov={users}|type=User|adapter={lambda u: (u.id, u.name)}|>
<taipy:selector lov="{users}" type="User" adapter="{lambda u: (u.id, u.name)}">{user_sel}</taipy:selector>

In this example, we are using the Python list users as the selector's list of values. Because the control needs a way to convert the list items (which are instances of the class User) into a string that can be displayed, we are using an adapter: a function that converts an object, whose type must be provided to the type property, to a tuple. The first element of the tuple is used to reference the selection (therefore those elements should be unique among all the items) and the second element is the string that turns out to be displayed.