Skip to content

Controls & Parameters

Switch

A switch allowing the user to select on/true or off/false

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
initial bool

The initial value of the parameter.

False

control = dp.Switch("enabled", label="Select enable or disabled")

TextBox

A single-line text field where the user can enter data.

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
initial str

The initial value of the parameter.

''
allow_empty bool

Whether to allow the user to enter an empty string.

False

control = dp.TextBox("input", label="Input your value")

NumberBox

A number field where the user can enter data.

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
initial float

The initial value of the parameter.

0

control = dp.NumberBox("input", label="Input your value", initial=0)

Range

A slider where the user can select a value within a range.

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
initial Numeric

The initial value of the parameter.

required
min Numeric

The minimum allowed value of the parameter.

required
max Numeric

The maximum allowed value of the parameter.

required
step t.Optional[Numeric]

The step size of the parameter.

None

control = dp.Range("age", initial=20, min=1, max=120, step=1)

Choice

A drop-down allowing the selection of a single value from a list.

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
options SList

The list of options to choose from.

required
initial t.Optional[str]

The initial value of the parameter.

None

control = dp.Choice("choice", initial="English", options=["English", "German", "French"])

MultiChoice

A drop-down allowing the selection of a multiple values from a list.

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
options SList

The list of options to choose from.

required
initial SList

The initial value of the parameter.

[]
allow_empty bool

Whether to allow the user to select no options.

False

control = dp.MultiChoice(
    "choice",
    initial=["Lettuce", "Cucumber"],
    options=["Lettuce", "Onion", "Cucumber", "Pickles"],
)

Tags

A drop-down allowing the selection of multiple values from a list. Allows adding new items to the list.

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
initial SList

An initial selection of tags

[]
allow_empty bool

Whether to allow the user to select no tags.

False

control = dp.Tags(
    "choice",
    label="Filter by multiple tags",
    initial=["#data", "#python", "#programming"],
)

Date

A control allowing the selection of a date (dd/mm/yyyy).

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
initial t.Optional[date]

The initial value of the parameter.

None

control = dp.Date("choice", label="Select a date", initial=datetime.date.today())

Time

A control allowing the entry of a time (hh:mm:ss).

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
initial t.Optional[time]

The initial value of the parameter.

None

control = dp.Time("choice", label="Enter a time")

DateTime

A control allowing the selection of a date and time (dd/mm/yyyy, hh:mm:ss).

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
initial t.Optional[datetime]

The initial value of the parameter.

None

control = dp.DateTime(
    "choice", label="Select a date and time", initial=datetime.datetime.now()
)

File

A control allowing the upload of a File from the user's device. Max size 25MB

Parameters:

Name Type Description Default
name t.Optional[str]

The name of the parameter.

None
label t.Optional[str]

The label of the parameter, visible to the user.

None
initial t.Optional[B64Path]

The initial value of the parameter.

None
allow_empty bool

Whether to allow the user to not upload a file.

False

control = dp.File("data", label="Upload a CSV file")