{ "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": [ "For a large variety of use cases we do not need complete control over the exact layout of each individual component on the page we just want to achieve a more polished look and feel. For these cases Panel ships with a number of default templates, which are defined by declaring three main content areas on the page, which can be populated as desired:\n", "\n", "* **`header`**: The header area of the HTML page\n", "* **`sidebar`**: A collapsible sidebar\n", "* **`main`**: The main area of the application\n", "\n", "These three areas behave very similarly to other Panel layout components and have list-like semantics. This means we can easily append new components into these areas. Unlike other layout components however, the contents of the areas is fixed once rendered. If you need a dynamic layout you should therefore insert a regular Panel layout component (e.g. a `Column` or `Row`) and modify it in place once added to one of the content areas. \n", "\n", "Templates can allow for us to quickly and easily create web apps for displaying our data. Panel comes with a default Template, and includes multiple Templates that extend the default which add some customization for a better display.\n", "\n", "________" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this case we are using the `GoldenTemplate`, built using the Golden Layout CSS, which allows for the creation of tabs that can be moved around. Here is an example of how you can set up a display using this template:" ] }, { "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()\n", "\n", "golden = pn.template.GoldenTemplate(title='Golden Template', theme=pn.template.DarkTheme)\n", "\n", "pn.config.sizing_mode = 'stretch_width'\n", "\n", "xs = np.linspace(0, np.pi)\n", "freq = pn.widgets.FloatSlider(name=\"Frequency\", start=0, end=10, value=2)\n", "phase = pn.widgets.FloatSlider(name=\"Phase\", start=0, end=np.pi)\n", "\n", "@pn.depends(freq=freq, phase=phase)\n", "def sine(freq, phase):\n", " return hv.Curve((xs, np.sin(xs*freq+phase))).opts(\n", " responsive=True, min_height=400)\n", "\n", "@pn.depends(freq=freq, phase=phase)\n", "def cosine(freq, phase):\n", " return hv.Curve((xs, np.cos(xs*freq+phase))).opts(\n", " responsive=True, min_height=400)\n", "\n", "golden.sidebar.append(freq)\n", "golden.sidebar.append(phase)\n", "\n", "golden.main.append(\n", " pn.Row(\n", " pn.Card(hv.DynamicMap(sine), title='Sine'),\n", " pn.Card(hv.DynamicMap(cosine), title='Cosine')\n", " )\n", ")\n", "golden.main.append(\n", " pn.Row(\n", " pn.Card(hv.DynamicMap(sine), title='Sine'),\n", " pn.Card(hv.DynamicMap(cosine), title='Cosine')\n", " )\n", ")\n", "\n", "golden.servable()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The app can be displayed within the notebook by using `.servable()`, or rendered in another tab by replacing it with `.show()`." ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }