{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "parameters" ] }, "outputs": [], "source": [ "flex_subtitle = \"built using jupyter-flex\"\n", "flex_external_link = \"https://github.com/danielfrg/jupyter-flex/blob/master/examples/widgets/ipysheet.ipynb\"\n", "\n", "flex_orientation = \"rows\"\n", "flex_show_source = True" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipysheet" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Page 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Row 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Sheet 1" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "body" ] }, "outputs": [], "source": [ "sheet = ipysheet.sheet(rows=3, columns=4)\n", "cell1 = ipysheet.cell(0, 0, 'Hello')\n", "cell2 = ipysheet.cell(2, 0, 'World')\n", "cell_value = ipysheet.cell(2,2, 42.)\n", "sheet" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Row 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Cell ranges" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "body" ] }, "outputs": [], "source": [ "sheet = ipysheet.sheet(rows=5, columns=4)\n", "row = ipysheet.row(0, [0, 1, 2, 3], background_color=\"red\")\n", "column = ipysheet.column(1, [\"a\", \"b\", \"c\", \"d\"], row_start=1, background_color=\"green\")\n", "cells = ipysheet.cell_range([[\"hi\", \"ola\"], [\"ciao\", \"bonjour\"], [\"hallo\", \"guten tag\"]],\n", " row_start=1, column_start=2, background_color=\"yellow\")\n", "sheet\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Page 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Row 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Jupyter widget events" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipywidgets as widgets\n", "sheet = ipysheet.sheet(rows=3, columns=2, column_headers=False, row_headers=False)\n", "cell_a = ipysheet.cell(0, 1, 1, label_left='a')\n", "cell_b = ipysheet.cell(1, 1, 2, label_left='b')\n", "cell_sum = ipysheet.cell(2, 1, 3, label_left='sum', read_only=True)\n", "\n", "# create a slider linked to cell a\n", "slider = widgets.FloatSlider(min=-10, max=10, description='a')\n", "widgets.jslink((cell_a, 'value'), (slider, 'value'))\n", "\n", "# changes in a or b should trigger this function\n", "def calculate(change):\n", " cell_sum.value = cell_a.value + cell_b.value\n", "\n", "cell_a.observe(calculate, 'value')\n", "cell_b.observe(calculate, 'value')\n", "\n", "widgets.VBox([sheet, slider])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Row 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### IPySheet calculation" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "body" ] }, "outputs": [], "source": [ "import ipywidgets as widgets\n", "sheet_2 = ipysheet.sheet(rows=3, columns=2, column_headers=False, row_headers=False)\n", "cell_a_2 = ipysheet.cell(0, 1, 1, label_left='a')\n", "cell_b_2 = ipysheet.cell(1, 1, 2, label_left='b')\n", "cell_sum_2 = ipysheet.cell(2, 1, 3, label_left='sum', read_only=True)\n", "\n", "# create a slider linked to cell a\n", "slider_2 = widgets.FloatSlider(min=-10, max=10, description='a')\n", "widgets.jslink((cell_a_2, 'value'), (slider_2, 'value'))\n", "\n", "@ipysheet.calculation(inputs=[cell_a_2, cell_b_2], output=cell_sum_2)\n", "def calculate(a, b):\n", " return a * b\n", "\n", "widgets.VBox([sheet_2, slider_2])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }