{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import panel as pn\n",
    "\n",
    "pn.extension(sizing_mode=\"stretch_width\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This example demonstrates **how to control one set of widgets with another set of widgets**, such as when the value of one widget changes the allowable values of another. Here the ``title_widget`` and ``value_widget`` control the title and ranges of the other set of widgets, respectively."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "title_widget = pn.widgets.TextInput(name='This controls labels', value='LABEL TEXT')\n",
    "value_widget = pn.widgets.IntSlider(name='This controls values', start=0, end=10, value=5)\n",
    "\n",
    "meta_widgets = pn.WidgetBox(\n",
    "    title_widget,\n",
    "    value_widget,\n",
    ")\n",
    "\n",
    "widgets = pn.WidgetBox(\n",
    "    pn.widgets.TextInput(),\n",
    "    pn.widgets.Spinner(),\n",
    "    pn.widgets.IntSlider(),\n",
    "    pn.widgets.RangeSlider(),\n",
    "    pn.widgets.FloatSlider(),\n",
    ")\n",
    "\n",
    "def update_titles(event):\n",
    "    for w in widgets:\n",
    "        w.name = '%s %s' % (w.__class__.__name__, event.new)\n",
    "\n",
    "title_widget.param.watch(update_titles, 'value')\n",
    "title_widget.param.trigger('value')\n",
    "\n",
    "def update_values(event):\n",
    "    for w in widgets:\n",
    "        if isinstance(w.value, (int, float)):\n",
    "            w.value = event.new\n",
    "            w.end = event.new\n",
    "\n",
    "value_widget.param.watch(update_values, 'value')\n",
    "\n",
    "pn.Row(meta_widgets, widgets)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## App\n",
    "\n",
    "Lets wrap it into nice template that can be served via `panel serve dynamic_widget_values.ipynb`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pn.template.FastListTemplate(site=\"Panel\", title=\"Dynamic Widget Labels and Values\", sidebar=[meta_widgets], main=[\"This example demonstrates **how to control one set of widgets with another set of widgets**.\", widgets]).servable();"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
