{ "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(sizing_mode='stretch_width')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example demonstrates the powerful streaming capabilities of the `Trend` indicator." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layout = pn.layout.FlexBox(*(\n", " pn.indicators.Trend(\n", " data={'x': list(range(10)), 'y': np.random.randn(10).cumsum()},\n", " width=150,\n", " height=100,\n", " plot_type=pn.indicators.Trend.param.plot_type.objects[i%4]\n", " ) for i in range(32)\n", "))\n", "\n", "def stream():\n", " for trend in layout:\n", " trend.stream({'x': [trend.data['x'][-1]+1], 'y': [trend.data['y'][-1]+np.random.randn()]}, rollover=20)\n", "\n", "cb = pn.state.add_periodic_callback(stream, 500)\n", "\n", "pn.Card(layout)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## App\n", "\n", "Lets wrap it into nice template that can be served via `panel serve streaming_trend.ipynb`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "controls = pn.Row(*pn.Param(cb.param, parameters=['period', 'running'], show_name=False, width=300))\n", "controls[1].align='end'\n", "\n", "pn.template.FastListTemplate(\n", " site=\"Panel\", \n", " title=\"Streaming Trend\", \n", " main=[\n", " \"This example demonstrates the **powerful streaming capabilities** of Panel and the `Trend` indicator.\",\n", " controls,\n", " layout,\n", " ]\n", ").servable();" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }