{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import panel as pn\n",
    "\n",
    "pn.extension('perspective', sizing_mode='stretch_width')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This example demonstrates the powerful streaming capabilities of the `Perspective` pane."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(np.random.randn(10, 4), columns=list('ABCD')).cumsum()\n",
    "\n",
    "rollover = pn.widgets.IntInput(name='Rollover', value=15)\n",
    "\n",
    "perspective = pn.pane.Perspective(\n",
    "    df, sizing_mode='stretch_width', height=400, theme='material-dark'\n",
    ")\n",
    "\n",
    "def stream():\n",
    "    data = df.iloc[-1] + np.random.randn(4)\n",
    "    perspective.stream(data, rollover=rollover.value)\n",
    "\n",
    "cb = pn.state.add_periodic_callback(stream, 50)\n",
    "\n",
    "component = pn.Column(\n",
    "    pn.Row(cb.param.period, rollover, perspective.param.theme),\n",
    "    perspective,\n",
    "    pn.layout.HSpacer(height=35), # Needed if user selects vaporwave theme in template\n",
    ")\n",
    "component"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## App\n",
    "\n",
    "Lets wrap it into nice template that can be served via `panel serve streaming_perspective.ipynb`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pn.template.FastListTemplate(\n",
    "    site=\"Panel\", \n",
    "    title=\"Streaming Perspective\", \n",
    "    main=[\n",
    "        \"This example demonstrates the **powerful streaming capabilities** of Panel and the `Perspective` pane.\",\n",
    "        component,\n",
    "    ]\n",
    ").servable();"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
