{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import datetime as dt\n", "\n", "import panel as pn\n", "import panel_material_ui as pmui\n", "\n", "pn.extension()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `DateSlider` widget allows selecting selecting a date value within a set bounds using a slider.\n", "\n", "Discover more on using widgets to add interactivity to your applications in the [how-to guides on interactivity](https://panel.holoviz.org/how_to/interactivity/index.html). Alternatively, learn [how to set up callbacks and (JS-)links between parameters](https://panel.holoviz.org/how_to/links/index.html) or [how to use them as part of declarative UIs with Param](https://panel.holoviz.org/how_to/param/index.html).\n", "\n", "#### Parameters:\n", "\n", "For details on other options for customizing the component see the [customization guides](https://panel-material-ui.holoviz.org/customization/index.html).\n", "\n", "##### Core\n", "\n", "* **`as_datetime`**: Whether to return value as a date (default) or datetime\n", "* **`disabled`** (boolean): Whether the widget is editable\n", "* **`start`** (date or datetime): The range's lower bound\n", "* **`step`** (integer): The selected step i the slider in days\n", "* **`end`** (date or datetime): The range's upper bound\n", "* **`value`** (date or datetime): The selected value as a datetime type\n", "* **`value_throttled`** (datetime): The selected value as a datetime type throttled until mouseup\n", "\n", "##### Display\n", "\n", "* **`bar_color`** (color): Color of the slider bar as a hexadecimal RGB value.\n", "* **`direction`** (`str`): Whether the slider should go from left to right ('ltr') or right to left ('rtl').\n", "* **`format`** (string): The datetime's format\n", "* **`label`** (`str`): The title of the widget.\n", "* **`marks`** (`boolean | list[dict]`): Marks indicate predetermined values to which the user can move the slider. If True the `options` are shown as marks. If a list, it should contain dicts with 'value' and an optional 'label' keys.\n", "* **`orientation`** (`Literal[\"horizonta\", \"vertical\"]`): Whether the slider should be displayed in a 'horizontal' or 'vertical' orientation.\n", "* **`show_value`** (`boolean`): Whether to show the widget value as a label or not. \n", "* **`tooltips`** (`boolean | Literal[\"auto\"]`): Whether to display tooltips on the slider handle.\n", "* **`track`** (`Literal[\"normal\", \"inverted\"]`): Whether to display 'normal' or 'inverted'.\n", "\n", "##### Styling\n", "\n", "- **`sx`** (dict): Component level styling API.\n", "- **`theme_config`** (dict): Theming API.\n", "\n", "##### Aliases\n", "\n", "For compatibility with Panel certain parameters are allowed as aliases:\n", "\n", "- **`name`**: Alias for `label`\n", "\n", "___" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "date_slider = pmui.DateSlider(label='Date Slider', start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8))\n", "\n", "date_slider" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "``DateSlider.value`` returns a datetime type that can be read out or set like other widgets:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "date_slider.value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Label\n", "\n", "You may remove the `label`/ `name` by not setting it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.DateSlider(start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Show Value\n", "\n", "You may remove the value label by setting `show_value=False`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.DateSlider(start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8), show_value=False, label='DateSlider')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Disabled\n", "\n", "The widget can be disabled with `disabled=True`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.DateSlider(label='Date Slider (disabled)', disabled=True, start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Color\n", "\n", "You can specify a `color`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.FlexBox(*(\n", " pmui.DateSlider(label=f'Date Slider ({color})', color=color, start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8))\n", " for color in pmui.DateSlider.param.color.objects\n", "))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Sizes\n", "\n", "For smaller slider, use the parameter `size=\"small\"`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.Row(\n", " pmui.DateSlider(label='Date Slider', size=\"small\", start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8)),\n", " pmui.DateSlider(label='Date Slider', size=\"medium\", start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8)),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Custom Marks\n", "\n", "You can have custom marks by providing a rich list to the `marks` parameter. Note that unlike continuous sliders the `value` of the marks should be the integer index of the option." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "marks = [\n", " {\n", " \"value\": dt.datetime(2019, 1, 1),\n", " \"label\": \"01/01\",\n", " },\n", " {\n", " \"value\": dt.datetime(2019, 3, 1),\n", " \"label\": \"03/01\",\n", " },\n", " {\n", " \"value\": dt.datetime(2019, 5, 1),\n", " \"label\": \"05/01\",\n", " },\n", " {\n", " \"value\": dt.datetime(2019, 6, 1),\n", " \"label\": \"06/01\",\n", " } \n", "]\n", "\n", "pmui.DateSlider(marks=marks, start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tooltip always visible\n", "\n", "You can force the thumb label to be always visible with `tooltips=True`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.DateSlider(\n", " label='Date', tooltips=True, start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8)\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tracks\n", "\n", "The *track* can be inverted or removed with `track=\"inverted\"` and `track=False` respectively:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.Row(\n", " pmui.DateSlider(label='Date Slider', track=False, start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8)),\n", " pmui.DateSlider(label='Date Slider', track=\"inverted\", start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8))\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Vertical Sliders\n", "\n", "The `orientation` of a slider may be \"vertical\":" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.DateSlider(label='Date Slider', orientation=\"vertical\", start=dt.datetime(2019, 1, 1), end=dt.datetime(2019, 6, 1), value=dt.datetime(2019, 2, 8))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Controls\n", "\n", "The `DateSlider` widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.Row(date_slider.api(jslink=True), date_slider)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### References\n", "\n", "Discover more on using widgets to add interactivity to your applications in the [how-to guides on interactivity](https://panel.holoviz.org/how_to/interactivity/index.html).\n", "\n", "Learn [how to set up callbacks and (JS-)links between parameters](https://panel.holoviz.org/how_to/links/index.html) or [how to use them as part of declarative UIs with Param](https://panel.holoviz.org/how_to/param/index.html).\n", "\n", "See also the Material UI `DateSlider` [Reference](https://mui.com/material-ui/react-slider/) and [API](https://mui.com/material-ui/api/slider/) documentation for inspiration." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 4 }