{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import panel as pn\n",
    "pn.extension()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The ``Select`` widget allows selecting a ``value`` from a list or dictionary of ``options`` by selecting it from a dropdown menu or selection area. It falls into the broad category of single-value, option-selection widgets that provide a compatible API and include the [``RadioBoxGroup``](RadioBoxGroup.ipynb), [``AutocompleteInput``](AutocompleteInput.ipynb) and [``DiscreteSlider``](DiscreteSlider.ipynb) widgets.\n",
    "\n",
    "Discover more on using widgets to add interactivity to your applications in the [how-to guides on interactivity](../how_to/interactivity/index.md). Alternatively, learn [how to set up callbacks and (JS-)links between parameters](../../how_to/links/index.md) or [how to use them as part of declarative UIs with Param](../../how_to/param/index.html).\n",
    "\n",
    "#### Parameters:\n",
    "\n",
    "For details on other options for customizing the component see the [layout](../../how_to/layout/index.md) and [styling](../../how_to/styling/index.md) how-to guides.\n",
    "\n",
    "##### Core\n",
    "\n",
    "* **``options``** (list or dict): A list or dictionary of options to select from\n",
    "* **``disabled_options``** (list): Optional list of ``options`` that are disabled, i.e. unusable and un-clickable. If ``options`` is a dictionary the list items must be dictionary values.\n",
    "* **``groups``** (dict): A dictionary whose keys are used to visually group the options and whose values are either a list or a dictionary of options to select from. Mutually exclusive with ``options`` and valid only if ``size`` is 1.\n",
    "* **``size``** (int, default=1): Declares how many options are displayed at the same time. If set to 1 displays options as dropdown otherwise displays scrollable area.\n",
    "* **``value``** (object): The current value; must be one of the option values\n",
    "\n",
    "##### Display\n",
    "\n",
    "* **``disabled``** (boolean): Whether the widget is editable\n",
    "* **``name``** (str): The title of the widget\n",
    "\n",
    "___"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "select = pn.widgets.Select(name='Select', options=['Biology', 'Chemistry', 'Physics'])\n",
    "\n",
    "select"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Like most other widgets, ``Select`` has a value parameter that can be accessed or set:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "select.value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `options` parameter also accepts a dictionary whose keys are going to be the labels of the dropdown menu. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "select = pn.widgets.Select(name='Select', options={'Biology': 1, 'Chemistry': 2})\n",
    "\n",
    "select"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "select.value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Updating the value will display the right label."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "select.value = 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A subset of the displayed items can be disabled with `disabled_options`. The widget `value` cannot be set to one of the `disabled_options`, either programmatrically or with the user interface."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "select = pn.widgets.Select(name='Select', options=['Biology', 'Chemistry', 'Physics'], disabled_options=['Chemistry'])\n",
    "\n",
    "select"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The items displayed in the dropdown menu can be grouped visually (also known as *optgroup*) by setting the `groups` parameter **instead of** `options`. `groups` accepts a dictionary whose keys are used to group the options and whose values are defined similarly to how `options` are defined."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "select = pn.widgets.Select(name='Select', groups={'Europe': ['Greece', 'France'], 'Africa': ['Algeria', 'Congo']})\n",
    "\n",
    "select"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "select.value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Instead of a dropdown menu we can also select one option from a list by rendering multiple options at once using the `size` parameter:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "select_area = pn.widgets.Select(name='Select', options=['Biology', 'Chemistry', 'Physics'], size=2)\n",
    "\n",
    "select_area"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When `size` is set to a value greater than 1 the widget supports the `disabled_options` parameter but does not support `groups`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pn.widgets.Select(name='Select', options=['Biology', 'Chemistry', 'Physics'], size=2, disabled_options=['Chemistry'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Controls\n",
    "\n",
    "The `Select` 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": [
    "pn.Row(select.controls(jslink=True), select)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
