Dates¶
Single date¶
marimo.ui.date
¶
date(
start: Optional[date | str] = None,
stop: Optional[date | str] = None,
value: Optional[date | str] = None,
*,
label: str = "",
on_change: Optional[Callable[[date], None]] = None,
full_width: bool = False
)
Bases: UIElement[str, date]
A date picker with an optional start and stop date.
Examples:
# create a date picker with bounds
date = mo.ui.date(
value="2022-06-01",
start="2022-01-01",
stop="2022-12-31",
)
Or from a dataframe series:
ATTRIBUTE | DESCRIPTION |
---|---|
value |
A str (YYYY-MM-DD) or
TYPE:
|
start |
The start date.
TYPE:
|
stop |
The stop date.
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
start
|
Minimum date selectable. If None, defaults to 01-01-0001.
TYPE:
|
stop
|
Maximum date selectable. If None, defaults to 12-31-9999.
TYPE:
|
value
|
Default date. If None and start and stop are None, defaults to the current day. If None and start is not None, defaults to start. If None and stop is not None, defaults to stop.
TYPE:
|
label
|
Markdown label for the element.
TYPE:
|
on_change
|
Optional callback to run when this element's value changes.
TYPE:
|
full_width
|
Whether the input should take up the full width of its container.
TYPE:
|
start
property
¶
Get the minimum selectable date.
RETURNS | DESCRIPTION |
---|---|
date
|
datetime.date: The start date, which is either the user-specified minimum date or 01-01-0001 if no start date was specified. |
stop
property
¶
Get the maximum selectable date.
RETURNS | DESCRIPTION |
---|---|
date
|
datetime.date: The stop date, which is either the user-specified maximum date or 12-31-9999 if no stop date was specified. |
batch
¶
batch(**elements: UIElement[JSONType, object]) -> batch
Convert an HTML object with templated text into a UI element.
This method lets you create custom UI elements that are represented by arbitrary HTML.
Example
user_info = mo.md(
'''
- What's your name?: {name}
- When were you born?: {birthday}
'''
).batch(name=mo.ui.text(), birthday=mo.ui.date())
In this example, user_info
is a UI Element whose output is markdown
and whose value is a dict with keys 'name'
and 'birthday
'
(and values equal to the values of their corresponding elements).
PARAMETER | DESCRIPTION |
---|---|
elements
|
the UI elements to interpolate into the HTML template.
TYPE:
|
callout
¶
callout(
kind: Literal[
"neutral", "danger", "warn", "success", "info"
] = "neutral"
) -> Html
Create a callout containing this HTML element.
A callout wraps your HTML element in a raised box, emphasizing its
importance. You can style the callout for different situations with the
kind
argument.
Examples:
form
¶
form(
label: str = "",
*,
bordered: bool = True,
loading: bool = False,
submit_button_label: str = "Submit",
submit_button_tooltip: Optional[str] = None,
submit_button_disabled: bool = False,
clear_on_submit: bool = False,
show_clear_button: bool = False,
clear_button_label: str = "Clear",
clear_button_tooltip: Optional[str] = None,
validate: Optional[
Callable[[Optional[JSONType]], Optional[str]]
] = None,
on_change: Optional[
Callable[[Optional[T]], None]
] = None
) -> form[S, T]
Create a submittable form out of this UIElement
.
Creates a form that gates submission of a UIElement
's value until a submit button is clicked.
The form's value is the value of the underlying element from the last submission.
Examples:
Convert any UIElement
into a form:
Combine with HTML.batch
to create a form made out of multiple UIElements
:
form = (
mo.ui.md(
'''
**Enter your prompt.**
{prompt}
**Choose a random seed.**
{seed}
'''
)
.batch(
prompt=mo.ui.text_area(),
seed=mo.ui.number(),
)
.form()
)
PARAMETER | DESCRIPTION |
---|---|
label
|
A text label for the form.
TYPE:
|
bordered
|
Whether the form should have a border.
TYPE:
|
loading
|
Whether the form should be in a loading state.
TYPE:
|
submit_button_label
|
The label of the submit button.
TYPE:
|
submit_button_tooltip
|
The tooltip of the submit button.
TYPE:
|
submit_button_disabled
|
Whether the submit button should be disabled.
TYPE:
|
clear_on_submit
|
Whether the form should clear its contents after submitting.
TYPE:
|
show_clear_button
|
Whether the form should show a clear button.
TYPE:
|
clear_button_label
|
The label of the clear button.
TYPE:
|
clear_button_tooltip
|
The tooltip of the clear button.
TYPE:
|
validate
|
A function that takes the form's value and returns an error message if invalid,
or
TYPE:
|
on_change
|
A callback that takes the form's value and returns an error message if invalid,
or
TYPE:
|
from_series
staticmethod
¶
Create a date picker from a dataframe series.
PARAMETER | DESCRIPTION |
---|---|
series
|
A pandas Series containing datetime values.
TYPE:
|
**kwargs
|
Additional keyword arguments passed to the date picker constructor. Supported arguments: start, stop, label, and any other date picker parameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
date
|
A date picker initialized with the series' min and max dates as bounds.
TYPE:
|
send_message
¶
Send a message to the element rendered on the frontend from the backend.
style
¶
style(
style: Optional[dict[str, Any]] = None, **kwargs: Any
) -> Html
Wrap an object in a styled container.
Example
PARAMETER | DESCRIPTION |
---|---|
style
|
an optional dict of CSS styles, keyed by property name
TYPE:
|
**kwargs
|
CSS styles as keyword arguments
TYPE:
|
:members:
Date and time¶
@app.cell
def __():
datetime = mo.ui.datetime(label="Start Date")
return
@app.cell
def __():
mo.hstack([datetime, mo.md(f"Has value: {datetime.value}")])
return
marimo.ui.datetime
¶
datetime(
start: Optional[datetime | str] = None,
stop: Optional[datetime | str] = None,
value: Optional[datetime | str] = None,
*,
label: Optional[str] = None,
on_change: Optional[
Callable[[Optional[datetime]], None]
] = None,
full_width: bool = False
)
Bases: UIElement[Optional[str], Optional[datetime]]
A datetime picker over an interval.
Examples:
datetime_picker = mo.ui.datetime(
start=dt.datetime(2023, 1, 1),
stop=dt.datetime(2023, 12, 31, 23, 59, 59),
)
Or from a dataframe series:
ATTRIBUTE | DESCRIPTION |
---|---|
value |
The selected datetime, possibly None.
TYPE:
|
start |
The minimum selectable datetime.
TYPE:
|
stop |
The maximum selectable datetime.
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
start
|
The minimum selectable datetime. Defaults to minimum datetime.
TYPE:
|
stop
|
The maximum selectable datetime. Defaults to maximum datetime.
TYPE:
|
value
|
Default value.
TYPE:
|
label
|
Markdown label for the element.
TYPE:
|
on_change
|
Optional callback to run when this element's value changes.
TYPE:
|
full_width
|
Whether the input should take up the full width of its container.
TYPE:
|
DATETIME_FORMAT
class-attribute
instance-attribute
¶
start
property
¶
Get the minimum selectable datetime.
RETURNS | DESCRIPTION |
---|---|
datetime
|
datetime.datetime: The start datetime, which is either the user-specified minimum datetime or datetime.min if no start datetime was specified. |
stop
property
¶
Get the maximum selectable datetime.
RETURNS | DESCRIPTION |
---|---|
datetime
|
datetime.datetime: The stop datetime, which is either the user-specified maximum datetime or datetime.max if no stop datetime was specified. |
batch
¶
batch(**elements: UIElement[JSONType, object]) -> batch
Convert an HTML object with templated text into a UI element.
This method lets you create custom UI elements that are represented by arbitrary HTML.
Example
user_info = mo.md(
'''
- What's your name?: {name}
- When were you born?: {birthday}
'''
).batch(name=mo.ui.text(), birthday=mo.ui.date())
In this example, user_info
is a UI Element whose output is markdown
and whose value is a dict with keys 'name'
and 'birthday
'
(and values equal to the values of their corresponding elements).
PARAMETER | DESCRIPTION |
---|---|
elements
|
the UI elements to interpolate into the HTML template.
TYPE:
|
callout
¶
callout(
kind: Literal[
"neutral", "danger", "warn", "success", "info"
] = "neutral"
) -> Html
Create a callout containing this HTML element.
A callout wraps your HTML element in a raised box, emphasizing its
importance. You can style the callout for different situations with the
kind
argument.
Examples:
form
¶
form(
label: str = "",
*,
bordered: bool = True,
loading: bool = False,
submit_button_label: str = "Submit",
submit_button_tooltip: Optional[str] = None,
submit_button_disabled: bool = False,
clear_on_submit: bool = False,
show_clear_button: bool = False,
clear_button_label: str = "Clear",
clear_button_tooltip: Optional[str] = None,
validate: Optional[
Callable[[Optional[JSONType]], Optional[str]]
] = None,
on_change: Optional[
Callable[[Optional[T]], None]
] = None
) -> form[S, T]
Create a submittable form out of this UIElement
.
Creates a form that gates submission of a UIElement
's value until a submit button is clicked.
The form's value is the value of the underlying element from the last submission.
Examples:
Convert any UIElement
into a form:
Combine with HTML.batch
to create a form made out of multiple UIElements
:
form = (
mo.ui.md(
'''
**Enter your prompt.**
{prompt}
**Choose a random seed.**
{seed}
'''
)
.batch(
prompt=mo.ui.text_area(),
seed=mo.ui.number(),
)
.form()
)
PARAMETER | DESCRIPTION |
---|---|
label
|
A text label for the form.
TYPE:
|
bordered
|
Whether the form should have a border.
TYPE:
|
loading
|
Whether the form should be in a loading state.
TYPE:
|
submit_button_label
|
The label of the submit button.
TYPE:
|
submit_button_tooltip
|
The tooltip of the submit button.
TYPE:
|
submit_button_disabled
|
Whether the submit button should be disabled.
TYPE:
|
clear_on_submit
|
Whether the form should clear its contents after submitting.
TYPE:
|
show_clear_button
|
Whether the form should show a clear button.
TYPE:
|
clear_button_label
|
The label of the clear button.
TYPE:
|
clear_button_tooltip
|
The tooltip of the clear button.
TYPE:
|
validate
|
A function that takes the form's value and returns an error message if invalid,
or
TYPE:
|
on_change
|
A callback that takes the form's value and returns an error message if invalid,
or
TYPE:
|
from_series
staticmethod
¶
Create a datetime picker from a dataframe series.
PARAMETER | DESCRIPTION |
---|---|
series
|
A pandas Series containing datetime values.
TYPE:
|
**kwargs
|
Additional keyword arguments passed to the datetime picker constructor. Supported arguments: start, stop, label, and any other datetime picker parameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
datetime
|
A datetime picker initialized with the series' min and max datetimes as bounds.
TYPE:
|
send_message
¶
Send a message to the element rendered on the frontend from the backend.
style
¶
style(
style: Optional[dict[str, Any]] = None, **kwargs: Any
) -> Html
Wrap an object in a styled container.
Example
PARAMETER | DESCRIPTION |
---|---|
style
|
an optional dict of CSS styles, keyed by property name
TYPE:
|
**kwargs
|
CSS styles as keyword arguments
TYPE:
|
:members:
Date range¶
marimo.ui.date_range
¶
date_range(
start: Optional[date | str] = None,
stop: Optional[date | str] = None,
value: Optional[
Tuple[date, date] | Tuple[str, str]
] = None,
*,
label: Optional[str] = None,
on_change: Optional[
Callable[[Tuple[date, date]], None]
] = None,
full_width: bool = False
)
Bases: UIElement[Tuple[str, str], Tuple[date, date]]
A date range picker over an interval.
Examples:
Or from a dataframe series:
ATTRIBUTE | DESCRIPTION |
---|---|
value |
A tuple of (start_date, end_date) representing the selected range.
TYPE:
|
start |
The minimum selectable date.
TYPE:
|
stop |
The maximum selectable date.
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
start
|
Minimum date selectable. If None, defaults to 01-01-0001.
TYPE:
|
stop
|
Maximum date selectable. If None, defaults to 12-31-9999.
TYPE:
|
value
|
Default value as (start_date, end_date). If None, defaults to (start, stop) if provided, otherwise today's date for both.
TYPE:
|
label
|
Markdown label for the element.
TYPE:
|
on_change
|
Optional callback to run when this element's value changes.
TYPE:
|
full_width
|
Whether the input should take up the full width of its container.
TYPE:
|
start
property
¶
Get the minimum selectable date.
RETURNS | DESCRIPTION |
---|---|
date
|
datetime.date: The start date, which is either the user-specified minimum date or 01-01-0001 if no start date was specified. |
stop
property
¶
Get the maximum selectable date.
RETURNS | DESCRIPTION |
---|---|
date
|
datetime.date: The stop date, which is either the user-specified maximum date or 12-31-9999 if no stop date was specified. |
batch
¶
batch(**elements: UIElement[JSONType, object]) -> batch
Convert an HTML object with templated text into a UI element.
This method lets you create custom UI elements that are represented by arbitrary HTML.
Example
user_info = mo.md(
'''
- What's your name?: {name}
- When were you born?: {birthday}
'''
).batch(name=mo.ui.text(), birthday=mo.ui.date())
In this example, user_info
is a UI Element whose output is markdown
and whose value is a dict with keys 'name'
and 'birthday
'
(and values equal to the values of their corresponding elements).
PARAMETER | DESCRIPTION |
---|---|
elements
|
the UI elements to interpolate into the HTML template.
TYPE:
|
callout
¶
callout(
kind: Literal[
"neutral", "danger", "warn", "success", "info"
] = "neutral"
) -> Html
Create a callout containing this HTML element.
A callout wraps your HTML element in a raised box, emphasizing its
importance. You can style the callout for different situations with the
kind
argument.
Examples:
form
¶
form(
label: str = "",
*,
bordered: bool = True,
loading: bool = False,
submit_button_label: str = "Submit",
submit_button_tooltip: Optional[str] = None,
submit_button_disabled: bool = False,
clear_on_submit: bool = False,
show_clear_button: bool = False,
clear_button_label: str = "Clear",
clear_button_tooltip: Optional[str] = None,
validate: Optional[
Callable[[Optional[JSONType]], Optional[str]]
] = None,
on_change: Optional[
Callable[[Optional[T]], None]
] = None
) -> form[S, T]
Create a submittable form out of this UIElement
.
Creates a form that gates submission of a UIElement
's value until a submit button is clicked.
The form's value is the value of the underlying element from the last submission.
Examples:
Convert any UIElement
into a form:
Combine with HTML.batch
to create a form made out of multiple UIElements
:
form = (
mo.ui.md(
'''
**Enter your prompt.**
{prompt}
**Choose a random seed.**
{seed}
'''
)
.batch(
prompt=mo.ui.text_area(),
seed=mo.ui.number(),
)
.form()
)
PARAMETER | DESCRIPTION |
---|---|
label
|
A text label for the form.
TYPE:
|
bordered
|
Whether the form should have a border.
TYPE:
|
loading
|
Whether the form should be in a loading state.
TYPE:
|
submit_button_label
|
The label of the submit button.
TYPE:
|
submit_button_tooltip
|
The tooltip of the submit button.
TYPE:
|
submit_button_disabled
|
Whether the submit button should be disabled.
TYPE:
|
clear_on_submit
|
Whether the form should clear its contents after submitting.
TYPE:
|
show_clear_button
|
Whether the form should show a clear button.
TYPE:
|
clear_button_label
|
The label of the clear button.
TYPE:
|
clear_button_tooltip
|
The tooltip of the clear button.
TYPE:
|
validate
|
A function that takes the form's value and returns an error message if invalid,
or
TYPE:
|
on_change
|
A callback that takes the form's value and returns an error message if invalid,
or
TYPE:
|
from_series
staticmethod
¶
Create a date range picker from a dataframe series.
PARAMETER | DESCRIPTION |
---|---|
series
|
A pandas Series containing datetime values.
TYPE:
|
**kwargs
|
Additional keyword arguments passed to the date range picker constructor. Supported arguments: start, stop, label, and any other date range picker parameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
date_range
|
A date range picker initialized with the series' min and max dates as bounds.
TYPE:
|
send_message
¶
Send a message to the element rendered on the frontend from the backend.
style
¶
style(
style: Optional[dict[str, Any]] = None, **kwargs: Any
) -> Html
Wrap an object in a styled container.
Example
PARAMETER | DESCRIPTION |
---|---|
style
|
an optional dict of CSS styles, keyed by property name
TYPE:
|
**kwargs
|
CSS styles as keyword arguments
TYPE:
|
:members: