{
 "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()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This example demonstrates how to dynamically add and remove plots from a layout (in this case a Column) using the ``pop`` and ``append`` methods (requires a live Pytbon server):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "slider = pn.widgets.IntSlider(name='N', start=0, end=5)\n",
    "\n",
    "column = pn.Column('This column will be populated with N Plots')\n",
    "\n",
    "def set_plots(event):\n",
    "    nplots = event.new-event.old\n",
    "    for i in range(abs(nplots)):\n",
    "        if nplots < 0:\n",
    "            column.pop(len(column)-1)\n",
    "        elif nplots > 0:\n",
    "            column.append(hv.Scatter(np.random.randn(1000, 2)))\n",
    "    \n",
    "slider.param.watch(set_plots, 'value')\n",
    "slider.value = 1\n",
    "\n",
    "pn.Row(slider, column).servable()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
