{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Jupyter JS Widgets\n", "\n", "BeakerX has a Groovy API for many of the [standard collection of widgets](https://ipywidgets.readthedocs.io/en/stable/). They are fully bidirectionally synchronized with the UI on the front-end. The work on their own, with [interactive recomputation](interactive.ipynb), and with [EasyForm](EasyForm.ipynb)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f8244048-d6e4-4ff0-b5db-9d71d32914ba", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.IntSlider\n", "\n", "w = new IntSlider()\n", "w.value = 60\n", "w" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "60" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.value" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "76" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.value = 76" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "description" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.description = \"description\"" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "false" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.disabled = false" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "50" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.max = 200\n", "w.min = 50" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "vertical" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.orientation = \"vertical\"" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#F04080" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.style.handle_color = \"#F04080\"" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "20" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.step = 20" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "false" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.layout.visibility = false" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9599e2d1-6939-45bf-b73b-6910be9d07c3", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.IntProgress\n", "bar = new IntProgress()\n", "bar.value = 10\n", "bar" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar.value" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "110" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar.value = 110" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "50" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar.max = 300\n", "bar.min = 50" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "20" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar.step = 20" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "horizontal" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar.orientation = 'horizontal'" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0961d0be-909d-4479-8d99-5096501af20b", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.RadioButtons\n", "rb = new RadioButtons()\n", "rb.options=['alpha', 'beta', 'delta', 'gamma']\n", "rb.value = 'beta'\n", "rb" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "beta" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rb.value" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "delta" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rb.value = 'delta'" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "709d5587-a4b3-40f0-b52a-227fb837cd95", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Select\n", "select = new Select()\n", "select.options=['Linux', 'Windows', 'OSX']\n", "select.value = 'Windows'\n", "select" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Windows" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "select.value" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Linux" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "select.value = 'Linux'" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d708da5d-9b54-46f9-897f-623001b89d70", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Checkbox\n", "cb = new Checkbox()\n", "cb" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "false" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cb.value" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cb.value = true" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b68bf2fd-113a-4848-a769-cce58c35c4de", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.ColorPicker\n", "cp = new ColorPicker()\n", "cp.value = \"blue\"\n", "cp" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "blue" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cp.value" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "red" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cp.value = 'red'" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "false" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cp.concise = false\n", "//cp.concise = true" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f5388f07-67ab-4fc1-85a2-15aff250606b", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Text\n", "t = new Text()\n", "t.value = \"Text example 1\"\n", "t" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Text example 1" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.value" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Text example 2" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.value =\"Text example 2\"" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f4691ab7-14de-4fc2-9ca4-903a45d3f245", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Textarea\n", "ta = new Textarea()\n", "ta.value = \"Textarea example 1\"\n", "ta" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Textarea example 1" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta.value" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Textarea example 2" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ta.value =\"Textarea example 2\"" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "27035a5a-e424-4050-b642-f42ec9a21d48", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.ToggleButton\n", "tb = new ToggleButton()\n", "tb.tooltip = \"ToggleButton tooltip 1\"\n", "tb.icon = 'check'\n", "tb.description = 'Click me'\n", "tb" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "false" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tb.value" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tb.value = true\n", "//tb.value = false" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ToggleButton tooltip 2" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tb.tooltip = \"ToggleButton tooltip 2\"" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d8cb820e-643e-430f-a0d4-e0545ebe5d4d", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.FloatSlider\n", "fs = new FloatSlider()\n", "fs.value = 10.1\n", "fs" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10.1" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fs.value" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "22.2" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fs.value = 22.2" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ef5d3c7d-f792-4c80-bb99-87e7904b95cf", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.FloatSlider\n", "fs = new FloatSlider()\n", "fs.max = 200\n", "fs. min = 10\n", "fs.value = 36.6\n", "fs.style.handle_color = \"orange\"\n", "fs" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b0e567af-4428-4b63-960c-3bfc9f75b6a4", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.FloatProgress\n", "floatProgress = new FloatProgress()\n", "floatProgress.value = 10.2\n", "floatProgress" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10.2" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "floatProgress.value" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "33.3" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "floatProgress.value = 33.3" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5987724a-8dd1-4d3d-bd36-63b8e30dece2", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Label\n", "label = new Label()\n", "label.value = \"Label 1\"\n", "label" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Label 1" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "label.value" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Label 2" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "label.value = \"Label 2\"" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "16d80f0f-206b-4b19-8d7f-1efbdbe30fbb", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.HTML\n", "label = new HTML()\n", "label.value = \"Hello World\"\n", "label" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Hello World" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "label.value = \"Hello World\"" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d50de03e-b62f-4e66-bd36-e57f2bac69c4", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Image\n", "import java.nio.file.Files\n", "\n", "byte[] picture = Files.readAllBytes(new File(\"../resources/img/widgetArch.png\").toPath());\n", "\n", "image = new Image()\n", "image.format='png'\n", "image.value= picture\n", "image.width=300\n", "image.height=400\n", "image" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "72a2ae76-db2e-40e2-ba77-32247674f8a8", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.DatePicker\n", "datePicker = new DatePicker()\n", "datePicker" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "null" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "datePicker.value" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b44194f3-d9f9-4bcf-9d39-e9e1cda1c235", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.IntRangeSlider\n", "w = new IntRangeSlider()\n", "w.value = [10,40]\n", "w.orientation = \"horizontal\"\n", "//w.orientation = \"vertical\"\n", "w" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2f706d11-0e12-47f3-a2fb-fba62292dafe", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.BoundedIntText\n", "w = new BoundedIntText()\n", "w.min = 0\n", "w.max = 10\n", "w" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6bb08201-64d0-4126-941c-e6e2cd0f0a1a", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.IntText\n", "w = new IntText()\n", "w" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9aab9cca-0523-4060-b5dd-37dae339bddb", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.IntText\n", "w = new IntText()\n", "w" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d8034e37-f798-459f-ba82-dcd5b7b943fd", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Play\n", "w = new Play()\n", "w" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c60083a3-c506-4764-aa14-5b633d473c14", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.FloatRangeSlider\n", "w = new FloatRangeSlider()\n", "w.value = [10,40]\n", "w.orientation = \"horizontal\"\n", "//w.orientation = \"vertical\"\n", "w" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a9ae3650-3a3e-471f-9085-4c38d9e16750", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.BoundedFloatText\n", "w = new BoundedFloatText()\n", "w.min = 0 \n", "w.max = 10\n", "w" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5b6d4e47-c7e5-464c-b1de-472f8ece507b", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.FloatText\n", "w = new FloatText()\n", "w" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "16a0d451-06e9-49de-95d1-59186e003f89", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "//Example with passing different type to value\n", "\n", "import com.twosigma.beakerx.widget.IntRangeSlider\n", "w = new IntRangeSlider()\n", "w.value = [\"10\",[49.6]]\n", "w.orientation = \"horizontal\"\n", "//w.orientation = \"vertical\"\n", "w" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "263d1f4c-af3c-415b-87f6-f87c64d8485d", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "//Example with passing different type to value\n", "\n", "import com.twosigma.beakerx.widget.IntRangeSlider\n", "import java.util.Collection\n", "\n", "Collection list = new ArrayList<>()\n", "list.add([\"19\"])\n", "list.add(\"53\")\n", "\n", "w = new IntRangeSlider()\n", "w.value = list\n", "w.orientation = \"horizontal\"\n", "//w.orientation = \"vertical\"\n", "w" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d5d0d8bc-d89c-4cb9-bfcd-141779883757", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Valid\n", "\n", "w = new Valid()\n", "w.description = 'Valid!'\n", "w.value = true\n", "w.disabled = false\n", "w" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c391c85d-2862-4ade-bf33-5764b9912fe9", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Accordion\n", "import com.twosigma.beakerx.widget.Valid\n", "import com.twosigma.beakerx.widget.BoundedFloatText\n", "import com.twosigma.beakerx.widget.Text\n", "\n", "t = new Text()\n", "t.value = \"Text example 1\"\n", "\n", "valid = new Valid()\n", "valid.description = 'Valid!'\n", "valid.value = true\n", "valid.disabled = false\n", "\n", "accordion = new Accordion([t , valid], ['t' , 'valid']);\n", "//accordion.set_title(0, 'Text')\n", "//accordion.set_title(1, 'Valid')\n", "accordion" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "647ee8f9-0104-45e4-b5ee-596be3abb89a", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Label\n", "widget = new Label()\n", "widget.value = \"\\$\\$\\\\frac{n!}{k!(n-k)!} = \\\\binom{n}{k}\\$\\$\"\n", "widget\n" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bcdae7e9-d1c2-4f7b-9c0d-4c526e954f87", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.SelectionSlider\n", "widget = new SelectionSlider()\n", "widget.options=['scrambled', 'sunny side up', 'poached', 'over easy']\n", "widget.value='sunny side up'\n", "widget.description='I like my eggs ...'\n", "widget.orientation='horizontal'\n", "//widget.orientation='vertical'\n", "widget" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e288e493-61b0-424a-9aac-22e7ec12f71f", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.HTMLMath\n", "widget = new HTMLMath()\n", "widget.value = \"\\$x^2\\$ and \\$\\$\\\\frac{x+1}{x-1}\\$\\$\"\n", "widget " ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "$x^2$ and $$\\frac{x+1}{x-1}$$" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "widget.value" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "924dfebc-7201-4498-a046-4e38c0e512e1", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.ToggleButtons\n", "widget = new ToggleButtons()\n", "widget.description='Speed:'\n", "widget.options=['Slow', 'Regular', 'Fast']\n", "widget.button_style = 'success'\n", "widget.tooltips=['SL', 'RE', 'Fast']\n", "widget.icons=['check', 'check', 'check']\n", "widget" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e11a80ca-657a-4ec8-aa05-98003eb13385", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.Play\n", "import com.twosigma.beakerx.widget.IntSlider\n", "import com.twosigma.beakerx.widget.HBox\n", "import com.twosigma.beakerx.widget.Link\n", "import com.twosigma.beakerx.widget.DirectionalLink\n", "import static com.twosigma.beakerx.widget.Link.jslink\n", "import static com.twosigma.beakerx.widget.DirectionalLink.jsdlink\n", "\n", "slider = new IntSlider()\n", "play= new Play()\n", "play.value=50\n", "play.min=0\n", "play.max=100\n", "//link = new Link(play, \"value\", slider, \"value\")\n", "link = jslink(play, \"value\", slider, \"value\")\n", "//link = new DirectionalLink(play, \"value\", slider, \"value\")\n", "//link = jsdlink(play, \"value\", slider, \"value\")\n", "box = new HBox([play,slider])\n" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f92d4a83-a926-41d9-ba69-045f882f3e54", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.IntSlider\n", "invisibleSlider = new IntSlider()\n", "invisibleSlider.max = 200\n", "invisibleSlider.min = 10\n", "invisibleSlider.value = 112\n", "invisibleSlider.layout.visibility = \"hidden\"\n", "invisibleSlider" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you are using slider widgets, you can set the continuous_update parameter to False. \n", "`continuous_update` is a parameter of slider widgets that restricts executions to mouse release events. \n", "To see diferrence try to move first slider and notice different of updating his value." ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "57071443-a726-4da9-9027-48f5614bf9b5", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.IntSlider\n", "import com.twosigma.beakerx.widget.HBox\n", "import com.twosigma.beakerx.widget.VBox\n", "\n", "continuosEnabled = new IntSlider()\n", "test = new HBox([continuosEnabled, continuosEnabled])\n" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e4519e87-fa59-4dc7-a8c7-a87e13002353", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import com.twosigma.beakerx.widget.IntSlider\n", "import com.twosigma.beakerx.widget.HBox\n", "import com.twosigma.beakerx.widget.VBox\n", "\n", "continuousDisabled = new IntSlider()\n", "continuousDisabled.continuous_update = false\n", "test = new HBox([continuousDisabled, continuousDisabled])\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "beakerx_kernel_parameters": {}, "kernelspec": { "display_name": "Groovy", "language": "groovy", "name": "groovy" }, "language_info": { "codemirror_mode": "groovy", "file_extension": ".groovy", "mimetype": "", "name": "Groovy", "nbconverter_exporter": "", "version": "2.4.3" }, "widgets": { "state": { "f6132997-5d22-4fbe-b4f9-16d41cb4e58b": { "views": [ { "cell_index": 0 } ] } }, "version": "1.2.0" } }, "nbformat": 4, "nbformat_minor": 1 }