{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Output Containers and Layout Managers\n", "\n", "Output containers are objects that hold a collection of other objects, and displays all its contents, even when they are complex interactive objects and MIME type.\n", "By default the contents are just stacked up on the page, but you can configure them to get tabs, a grid, or cycling." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Stacked Output Containers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from beakerx import *\n", "o = OutputContainer()\n", "o.addItem(\"simplest example\")\n", "o.addItem([2, 3, 5, 7])\n", "o.addItem(HTML(\"

title

\"))\n", "o.addItem(None)\n", "o" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rates = pd.read_csv('../resources/data/interest-rates.csv')\n", "c = Color(120, 120, 120, 100)\n", "plot1 = Plot(initWidth= 300, initHeight= 400) \n", "plot1.add(Points(x= rates.y1, y=rates.y30, size= 3, displayName=\"y1 vs y30\"))\n", "plot1.add(Line(x= rates.y1, y=rates.y30, color= c))\n", "plot1.add(Points(x= rates.m3, y=rates.y5, size= 3, displayName=\"m3 vs y5\"))\n", "plot1.add(Line(x= rates.m3, y=rates.y5, color= c))\n", "plot1.setShowLegend(False)\n", "plot2 = SimpleTimePlot(rates, [\"m3\", \"y1\"], showLegend=False, initWidth= 300, initHeight= 400)\n", "plot3 = SimpleTimePlot(rates, [\"y5\", \"y10\"], showLegend=False, initWidth= 300, initHeight= 400)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tabbed Output Containers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table = pd.DataFrame({'a' : [1, 2, 1, 5], 'b' : [\"a\", \"ab\", \"b\", \"ababa\"]})\n", "\n", "l = TabbedOutputContainerLayoutManager()\n", "l.setBorderDisplayed(False)\n", "o = OutputContainer()\n", "o.setLayoutManager(l)\n", "o.addItem(plot1, \"Scatter with History\")\n", "o.addItem(plot2, \"Short Term\")\n", "o.addItem(plot3, \"Long Term\")\n", "o.addItem(table, \"Pandas Table\")\n", "o" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Grid Output Containers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryPlot(initWidth= 300, initHeight= 400)\n", "bars.add(CategoryBars(value= [[1.1, 2.4, 3.8], [1, 3, 4]]))\n", "\n", "lg = GridOutputContainerLayoutManager(3)\n", "\n", "og = OutputContainer()\n", "og.setLayoutManager(lg)\n", "og.addItem(plot1, \"Scatter with History\")\n", "og.addItem(plot2, \"Short Term\")\n", "og.addItem(plot3, \"Long Term1\")\n", "og.addItem(bars, \"Bar Chart\")\n", "og.addItem(HTML(\"
something
\"))\n", "og.addItem(table, \"Pandas Table\")\n", "og" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cycling Output Container" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "l = CyclingOutputContainerLayoutManager()\n", "l.setPeriod(2345); # milliseconds\n", "l.setBorderDisplayed(False);\n", "o = OutputContainer()\n", "o.setLayoutManager(l)\n", "o.addItem(plot1, \"Scatter with History\")\n", "o.addItem(plot2, \"Short Term\")\n", "o.addItem(plot3, \"Long Term\")\n", "o" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 1 }