{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import panel as pn\n",
    "import hvplot.pandas\n",
    "\n",
    "from bokeh.sampledata.autompg import autompg_clean\n",
    "\n",
    "pn.extension()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This example demonstrates how to combine multiple columns of widgets into layout an overall layout."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "quant = [None, 'mpg', 'cyl', 'displ', 'hp', 'weight', 'yr']\n",
    "cat = [None, 'origin', 'mfr', 'yr']\n",
    "combined = quant+cat[1:]\n",
    "\n",
    "x = pn.widgets.Select(name='x', value='mpg', options=combined)\n",
    "y = pn.widgets.Select(name='y', value='cyl', options=combined)\n",
    "color = pn.widgets.Select(name='color', options=combined)\n",
    "facet = pn.widgets.Select(name='facet', options=cat)\n",
    "\n",
    "@pn.depends(x, y, color, facet)\n",
    "def plot(x, y, color, facet):\n",
    "    cmap = 'Category10' if color in cat else 'viridis'\n",
    "    return autompg_clean.hvplot.scatter(\n",
    "        x, y, color=color or 'darkblue', by=facet, subplots=True, padding=0.1,\n",
    "        cmap=cmap, responsive=True, min_height=300\n",
    "    )\n",
    "\n",
    "pn.Column(\n",
    "    '### Auto MPG Explorer', \n",
    "    plot,\n",
    "    pn.Row(pn.WidgetBox(x, y, color), pn.WidgetBox(facet)),\n",
    "    width_policy='max'\n",
    ").servable()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
