{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# ipyregulartable\n", "https://github.com/finos/ipyregulartable\n", " " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import ipyregulartable as rt" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import string\n", "from random import choice, sample, randint, random\n", "\n", "def _generateRandomData(n_rows=100):\n", " return np.array([\n", " ([_] + [randint(0, 100),\n", " ''.join(sample(string.ascii_lowercase, 5)),\n", " (random() * 100) - 50,\n", " choice((True, False))\n", " ]) for _ in range(n_rows)\n", " ])\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0c3daae77b9147b094ffbaf275caa07c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "RegularTableWidget(height=500)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "w = rt.RegularTableWidget(\n", " rt.NumpyDataModel(_generateRandomData()))\n", "w.height = 500\n", "w" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "w.css = {\"th\": \"background-color: rgba(0, 0, 0, .5); color: white; text-weight: bold;\"}" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "w.styler = {\n", " \"td\": {\n", " \"expression\": [\"y % 2 == 0\",\n", " \"y % 2 != 0\",\n", " \"(x == 1 or x == 3) and (data > 0)\",\n", " \"(x == 1 or x == 3) and (data < 0)\"],\n", " \"style\": [\"background-color:rgba(0, 0, 0, .1);\",\n", " \"background-color:white;\",\n", " \"color: red;\",\n", " \"color: green;\"]\n", " }\n", " }" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.7" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "0c3daae77b9147b094ffbaf275caa07c": { "model_module": "ipyregulartable", "model_module_version": "^0.1.2", "model_name": "RegularTableModel", "state": { "_data": { "column_headers": [ [ "0" ], [ "1" ], [ "2" ], [ "3" ], [ "4" ], [ "5" ], [ "6" ] ], "data": [ [ "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34" ], [ "84", "14", "51", "41", "47", "5", "7", "3", "85", "82", "30", "21", "21", "75", "42", "63", "73", "68", "11", "52", "93", "75", "81", "93", "22", "21", "98" ], [ "qvypa", "rahlk", "ovxed", "hvasf", "vioqb", "hqxnc", "shtax", "trdzp", "hmfng", "mljbk", "olsjm", "mgvxu", "udkov", "rzjmn", "gkhoq", "erlon", "rlbaj", "icqdm", "ajwlf", "dvqib", "hcqmn", "dkcgx", "rofje", "utgse", "sorkm", "uapix", "vtapr" ], [ "31.597333196356786", "32.86783076225291", "-36.26080036258685", "15.571552917720126", "-14.675850903965383", "-21.449305085932522", "-36.24855610539582", "-12.000374297850726", "-6.0481886306956625", "-20.11653501673438", "-32.07374872006591", "8.919372933642457", "9.796921609787837", "20.41179890496339", "27.11316963695036", "-32.013275096455075", "13.119943724599139", "-25.61996909325025", "-37.11286622583354", "-24.97494566989068", "48.81707599020058", "-23.4357693157904", "1.7347197289761453", "-45.98380691639704", "-41.86433063248993", "15.663767326168625", "44.71558398401454" ], [ "False", "False", "False", "True", "False", "False", "True", "False", "True", "True", "True", "False", "True", "False", "False", "True", "False", "True", "True", "False", "False", "True", "True", "False", "False", "True", "True" ] ], "num_columns": 5, "num_rows": 100, "row_headers": [ [ "8" ], [ "9" ], [ "10" ], [ "11" ], [ "12" ], [ "13" ], [ "14" ], [ "15" ], [ "16" ], [ "17" ], [ "18" ], [ "19" ], [ "20" ], [ "21" ], [ "22" ], [ "23" ], [ "24" ], [ "25" ], [ "26" ], [ "27" ], [ "28" ], [ "29" ], [ "30" ], [ "31" ], [ "32" ], [ "33" ] ] }, "_editable": true, "_model_module_version": "^0.1.2", "_view_module_version": "^0.1.2", "css": { "th": "background-color: rgba(0, 0, 0, .5); color: white; text-weight: bold;" }, "height": 500, "layout": "IPY_MODEL_29d35915e69f41ec85aeb08d3c435b27", "styler": { "td": { "expression": [ "y % 2 == 0", "y % 2 != 0", "(x == 1 or x == 3) and (data > 0)", "(x == 1 or x == 3) and (data < 0)" ], "style": [ "background-color:rgba(0, 0, 0, .1);", "background-color:white;", "color: red;", "color: green;" ] } } } }, "29d35915e69f41ec85aeb08d3c435b27": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "5e19278fc6ac40e78df967d97a343821": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "cf2cd7dee7b64e58ae7c90e5a815c59f": { "model_module": "ipyregulartable", "model_module_version": "^0.1.2", "model_name": "RegularTableModel", "state": { "_data": { "column_headers": [], "data": [], "num_columns": 5, "num_rows": 100, "row_headers": [] }, "_editable": true, "_model_module_version": "^0.1.2", "_view_module_version": "^0.1.2", "css": {}, "height": 500, "layout": "IPY_MODEL_5e19278fc6ac40e78df967d97a343821", "styler": {} } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }