{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import panel as pn\n",
    "pn.extension()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A ``ToggleGroup`` is a group of widgets which can be switched 'on' or 'off'.  \n",
    "This widget is a thin wrapper for using either a [CheckButtonGroup](CheckButtonGroup.ipynb), [CheckBoxGroup](Customization.ipynb),\n",
    "[RadioButtonGroup](Customization.ipynb) or [RadioBoxGroup](RadioBoxGroup.ipynb)\n",
    "to select between a single or multiple given values.\n",
    "\n",
    "For more information about listening to widget events and laying out widgets refer to the [widgets user guide](../../user_guide/Widgets.ipynb). Alternatively you can learn how to build GUIs by declaring parameters independently of any specific widgets in the [param user guide](../../user_guide/Param.ipynb). To express interactivity entirely using Javascript without the need for a Python server take a look at the [links user guide](../../user_guide/Param.ipynb).\n",
    "\n",
    "#### Parameters:\n",
    "\n",
    "For layout and styling related parameters see the [customization user guide](../../user_guide/Customization.ipynb).\n",
    "\n",
    "##### Core\n",
    "\n",
    "* **``widget_type``** (str): Two types of widgets are available: ``button`` (default) and ``box``\n",
    "* **``behavior``** (str): Two different behaviors are available: ``check`` (default) and ``radio``\n",
    "\n",
    "\n",
    "As the `ToggleGroup` class is just a Factory for other different widget types, the above parameters cannot be changed or set after instantion.\n",
    "All additional given parameters are passed through to the constructor of the resulting widget class.\n",
    "\n",
    "The different parameter combinations and the resulting widget type are shown in the following table.\n",
    "\n",
    "| widget_type | behavior  | Resulting Widget  |\n",
    "|---|---|---|\n",
    "| button  | check  |  [CheckButtonGroup](CheckButtonGroup.ipynb) |\n",
    "| button  | radio  |  [RadioButtonGroup](Customization.ipynb) |\n",
    "|  box | check  |  [CheckBoxGroup](Customization.ipynb) |\n",
    "| box  |  radio | [RadioBoxGroup](RadioBoxGroup.ipynb)  |\n",
    "\n",
    "\n",
    "___"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "toggle_group = pn.widgets.ToggleGroup(name='ToggleGroup', options=['Biology', 'Chemistry', 'Physics'])\n",
    "\n",
    "toggle_group"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Like most other widgets, ``ToggleGroup`` has a value parameter that can be accessed or set:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "toggle_group.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "toggle_group = pn.widgets.ToggleGroup(name='ToggleGroup', options=['Biology', 'Chemistry', 'Physics'], behavior=\"radio\")\n",
    "\n",
    "toggle_group"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For radio behavior the value is only a single value!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "toggle_group.value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The resulting object is not of type ToggleGroup but is an object dependent of the input parameters as shown in the `Parameters` section"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(toggle_group)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Controls\n",
    "\n",
    "The `ToggleGroup` widget (concretly the created, underlying 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(toggle_group.controls(jslink=True), toggle_group)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
