{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import panel as pn\n",
    "import numpy as np\n",
    "import holoviews as hv\n",
    "\n",
    "pn.extension(sizing_mode=\"stretch_width\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This example demonstrates how to plot several different types of outputs in a ``Tabs`` Panel, using a reactive function that depends on some widget state to update the tab contents whenever one of the dependencies changes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "distributions = {\n",
    "    'NORMAL': np.random.normal,\n",
    "    'UNIFORM': np.random.uniform,\n",
    "    'LOG-NORMAL': np.random.lognormal,\n",
    "    'EXPONENTIAL': np.random.exponential\n",
    "}\n",
    "\n",
    "checkboxes = pn.widgets.ToggleGroup(options=distributions, behavior='radio', button_type=\"success\")\n",
    "slider = pn.widgets.IntSlider(name='Number of observations', value=500, start=0, end=2000)\n",
    "\n",
    "@pn.depends(checkboxes.param.value, slider.param.value)\n",
    "def tabs(distribution, n):\n",
    "    values = hv.Dataset(distribution(size=n), 'values')\n",
    "    return pn.Tabs(\n",
    "        ('Plot', values.hist(adjoin=False).opts(\n",
    "            responsive=True, max_height=500, padding=0.1, color=\"#00aa41\")),\n",
    "        ('Summary', values.dframe().describe().T),\n",
    "        ('Table', hv.Table(values)),\n",
    "    )\n",
    "\n",
    "selections = pn.Column('### Distribution Type', checkboxes, slider)\n",
    "pn.Row(selections, tabs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## App\n",
    "\n",
    "Lets wrap it into nice template that can be served via `panel serve distribution_tabs.ipynb`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pn.template.FastListTemplate(site=\"Panel\", title=\"Distribution Tabs\", main=[\"This example demonstrates **how to plot several different types of outputs in a Tab**.\", selections, tabs]).servable();"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
