diff --git a/docs/demos/2023-02-28-community-demo.ipynb b/docs/demos/2023-02-28-community-demo.ipynb index 7de6ba1c..a20c5f09 100644 --- a/docs/demos/2023-02-28-community-demo.ipynb +++ b/docs/demos/2023-02-28-community-demo.ipynb @@ -12,17 +12,23 @@ "source": [ "# `pidgy` literate computing\n", "\n", - "you've heard of interactive computing, we'll call `pidgy` hyperactive computing. it is designed to help authors write their programs.\n", - "markdown is our programming language because it is inclusive AF.[^md]\n", + "you've heard of interactive computing, we'll call `pidgy` hyperactive computing. \n", "\n", + "\n", "\n", "
\n", " \n", @@ -47,20 +53,23 @@ "[community call]: https://hackmd.io/dcbps9AESEuP0N3j4mMOqw \"hackmd for the jupyter community call\"\n", "[^calls]: jupyter community calls are a monthly series of events to showcase what you are doing in and with jupyter. please consider submitting to or hosting a [future community call] sometime\n", "\n", - "[future community call]: https://discourse.jupyter.org/t/jupyter-community-calls/668 \"updating discourse announcement for the jupyter community calls.\"" + "[future community call]: https://discourse.jupyter.org/t/jupyter-community-calls/668 \"updating discourse announcement for the jupyter community calls.\"\n", + "\n", + "https://monoskop.org/images/b/be/Nelson_Ted_Literary_Machines_c1987_chs_0-1.pdf\n", + "https://pure.au.dk/ws/files/173226224/PPIG_2019_camera_ready.pdf" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "id": "dad20d9d-7d1e-477b-91ba-0e8139ed7e70", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:50:31.530423Z", - "iopub.status.busy": "2023-02-24T23:50:31.530227Z", - "iopub.status.idle": "2023-02-24T23:50:31.538187Z", - "shell.execute_reply": "2023-02-24T23:50:31.537785Z", - "shell.execute_reply.started": "2023-02-24T23:50:31.530408Z" + "iopub.execute_input": "2023-03-03T03:04:18.388033Z", + "iopub.status.busy": "2023-03-03T03:04:18.387862Z", + "iopub.status.idle": "2023-03-03T03:04:18.521450Z", + "shell.execute_reply": "2023-03-03T03:04:18.521047Z", + "shell.execute_reply.started": "2023-03-03T03:04:18.388015Z" }, "slideshow": { "slide_type": "slide" @@ -80,10 +89,11 @@ " # in that case we recommend the hybrid `.md.ipynb` extension.\n", " \n", " if LITE := (__import__(\"sys\").platform == \"emscripten\"): # compatability for jupyterlite\n", - " %pip install pandas pidgy matplotlib ipywidgets\n", + " %pip install pandas pidgy matplotlib ipywidgets toolz\n", " \n", " # activate pidgy\n", - " %reload_ext pidgy" + " %reload_ext pidgy\n", + " from toolz.curried import *" ], "text/plain": [ "" @@ -103,10 +113,11 @@ " # in that case we recommend the hybrid `.md.ipynb` extension.\n", " \n", " if LITE := (__import__(\"sys\").platform == \"emscripten\"): # compatability for jupyterlite\n", - " %pip install pandas pidgy matplotlib ipywidgets\n", + " %pip install pandas pidgy matplotlib ipywidgets toolz\n", " \n", " # activate pidgy\n", - " %reload_ext pidgy" + " %reload_ext pidgy\n", + " from toolz.curried import *" ] }, { @@ -126,27 +137,31 @@ "tags": [] }, "source": [ - "## the `pidgy` metalanguage\n", + "## the `pidgy` polyglot metalanguage\n", "\n", "`pidgy` is a [pidgin] [metalanguage] of python programming and jinja templates embedded inside markdown.\n", "literate programming is that aim to craft documentation and code at the same time.\n", "literate computing is when we do this interactively, and weave live computing into the narrative.\n", "\n", + "\n", "[pidgin]: https://en.wikipedia.org/wiki/Pidgin\n", "[metalanguage]: https://en.wikipedia.org/wiki/Metalanguage" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 2, "id": "9c822c6c-d04c-4a0a-91ea-eed3e62006a3", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:51:36.102369Z", - "iopub.status.busy": "2023-02-24T23:51:36.102092Z", - "iopub.status.idle": "2023-02-24T23:51:36.113075Z", - "shell.execute_reply": "2023-02-24T23:51:36.112702Z", - "shell.execute_reply.started": "2023-02-24T23:51:36.102346Z" + "iopub.execute_input": "2023-03-03T03:04:18.524066Z", + "iopub.status.busy": "2023-03-03T03:04:18.523849Z", + "iopub.status.idle": "2023-03-03T03:04:18.553489Z", + "shell.execute_reply": "2023-03-03T03:04:18.553106Z", + "shell.execute_reply.started": "2023-03-03T03:04:18.524048Z" + }, + "jupyter": { + "source_hidden": true }, "slideshow": { "slide_type": "fragment" @@ -157,12 +172,12 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "da04dd6c660f427a90d35e315256e2e9", + "model_id": "a59df83a6d58485bb5d8618256e25abc", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Checkbox(value=False, description='show more languages')" + "IntSlider(value=6, description='show more languages', max=6, min=1)" ] }, "metadata": {}, @@ -172,23 +187,42 @@ "data": { "text/markdown": [ "
\n", - "
the REPL overlayed with a literate computing workflow of tangle and weave.
\n", + "
\n", + "\n", + "the REPL overlayed with a [literate computing] workflow of tangle and weave.\n", + "\n", + "
\n", + "\n", "\n", "```mermaid\n", "flowchart LR\n", - " input[markdown]--tangle\\nread-->IPython--eval/template-->jinja--weave\\nprint-->output[markdown]-.loop-.->input\n", - " %% html ---> input; css ---> input; javascript ---> input\n", - " %% julia ---> magics; r---> magics; fortran ---> magics; magics ---> IPython\n", + "\n", + "\n", + "\n", + " input[markdown]--tangle\\nread-->IPython\n", + "\n", + " IPython--eval/template-->jinja\n", + "\n", + " jinja--weave\\nprint-->output[markdown]\n", + "\n", + " output[markdown]-.loop-.->input\n", + "\n", + " html ---> input; css ---> input; javascript ---> input\n", + "\n", + " julia ---> magics; r---> magics; fortran ---> magics; magics ---> IPython\n", + "\n", "```\n", - "
extended markdown syntax is provided by jupyterlab-markup
\n", + "
mermaid graph syntax uses extended markdown syntax provided by jupyterlab-markup
\n", "
\n", "\n", - " display(extra := Checkbox(description=\"show more languages\"))\n", + " display(extra := IntSlider(6, min=1, max=6, description=\"show more languages\")) # 6 lines in the graph\n", "\n", "`pidgy` is interested in exploring the interfaces of languages in computational essays. each language provides extra syntax for telling your story. with markdown we can include html, css, and javascript; code blocks can include more languages like mermaid. [IPython is our polyglot glue language][polyglot notebook]. \n", "\n", "[literate computing]: #\n", - "[polyglot notebook]: https://gist.github.com/fperez/5b49246af4e340c37549265a90894ce6 \"fperez's polyglot juypyter demo\"" + "[polyglot notebook]: https://gist.github.com/fperez/5b49246af4e340c37549265a90894ce6 \"fperez's polyglot juypyter demo\"\n", + "\n", + "[fperez lc]: https://web.archive.org/web/20220510083647/http://blog.fperez.org/2013/04/literate-computing-and-computational.html" ], "text/plain": [ "" @@ -200,23 +234,37 @@ ], "source": [ "
\n", - "
the REPL overlayed with a literate computing workflow of tangle and weave.
\n", + "
\n", "\n", + "the REPL overlayed with a [literate computing] workflow of tangle and weave.\n", + "\n", + "
\n", + "\n", + "{% set repl %}\n", + " input[markdown]--tangle\\nread-->IPython\n", + " IPython--eval/template-->jinja\n", + " jinja--weave\\nprint-->output[markdown]\n", + " output[markdown]-.loop-.->input\n", + " html ---> input; css ---> input; javascript ---> input\n", + " julia ---> magics; r---> magics; fortran ---> magics; magics ---> IPython\n", + "{% endset %}\n", "```mermaid\n", "flowchart LR\n", - " input[markdown]--tangle\\nread-->IPython--eval/template-->jinja--weave\\nprint-->output[markdown]-.loop-.->input\n", - " {% if not extra.value %}%%{% endif %} html ---> input; css ---> input; javascript ---> input\n", - " {% if not extra.value %}%%{% endif %} julia ---> magics; r---> magics; fortran ---> magics; magics ---> IPython\n", + "{% for i, line in enumerate(repl.splitlines()) %}\n", + "{% if i > extra.value %}%%{% endif %}{{line}}\n", + "{% endfor %}\n", "```\n", - "
extended markdown syntax is provided by jupyterlab-markup
\n", + "
mermaid graph syntax uses extended markdown syntax provided by jupyterlab-markup
\n", "
\n", "\n", - " display(extra := Checkbox(description=\"show more languages\"))\n", + " display(extra := IntSlider(6, min=1, max=6, description=\"show more languages\")) # 6 lines in the graph\n", "\n", "`pidgy` is interested in exploring the interfaces of languages in computational essays. each language provides extra syntax for telling your story. with markdown we can include html, css, and javascript; code blocks can include more languages like mermaid. [IPython is our polyglot glue language][polyglot notebook]. \n", "\n", "[literate computing]: #\n", - "[polyglot notebook]: https://gist.github.com/fperez/5b49246af4e340c37549265a90894ce6 \"fperez's polyglot juypyter demo\"" + "[polyglot notebook]: https://gist.github.com/fperez/5b49246af4e340c37549265a90894ce6 \"fperez's polyglot juypyter demo\"\n", + "\n", + "[fperez lc]: https://web.archive.org/web/20220510083647/http://blog.fperez.org/2013/04/literate-computing-and-computational.html" ] }, { @@ -239,20 +287,23 @@ "\n", "the `%%tangle` magic tangles markdown to python code for previewing and debugging. this magic will help you learn `pidgy`s indenting [heuristics and language features provided by `midgy`][midgy basics].\n", "\n", - "[midgy basics]: https://deathbeds.github.io/midgy/language/basics/https://deathbeds.github.io/midgy/language/basics/" + "[midgy basics]: https://deathbeds.github.io/midgy/language/basics/" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 3, "id": "ab55d44b-2838-4742-a76b-761ac30fcfb0", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:51:55.953544Z", - "iopub.status.busy": "2023-02-24T23:51:55.953337Z", - "iopub.status.idle": "2023-02-24T23:51:55.958725Z", - "shell.execute_reply": "2023-02-24T23:51:55.958404Z", - "shell.execute_reply.started": "2023-02-24T23:51:55.953529Z" + "iopub.execute_input": "2023-03-03T03:04:18.554094Z", + "iopub.status.busy": "2023-03-03T03:04:18.553974Z", + "iopub.status.idle": "2023-03-03T03:04:18.689810Z", + "shell.execute_reply": "2023-03-03T03:04:18.689380Z", + "shell.execute_reply.started": "2023-03-03T03:04:18.554083Z" + }, + "jupyter": { + "source_hidden": true }, "slideshow": { "slide_type": "fragment" @@ -393,7 +444,7 @@ "\"\"\"https://api.github.com\"\"\";" ] }, - "execution_count": 11, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -440,15 +491,15 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 4, "id": "f4b42a15-1406-4c58-8552-5bd0761eb9d3", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:51:56.836149Z", - "iopub.status.busy": "2023-02-24T23:51:56.835638Z", - "iopub.status.idle": "2023-02-24T23:51:56.845334Z", - "shell.execute_reply": "2023-02-24T23:51:56.844924Z", - "shell.execute_reply.started": "2023-02-24T23:51:56.836101Z" + "iopub.execute_input": "2023-03-03T03:04:18.690695Z", + "iopub.status.busy": "2023-03-03T03:04:18.690504Z", + "iopub.status.idle": "2023-03-03T03:04:18.698578Z", + "shell.execute_reply": "2023-03-03T03:04:18.698159Z", + "shell.execute_reply.started": "2023-03-03T03:04:18.690675Z" }, "slideshow": { "slide_type": "subslide" @@ -460,7 +511,11 @@ "data": { "text/markdown": [ "
\n", - "
a mermaid homage to the dual usage of the WEB file format being translated to a document and programming language.
\n", + "
\n", + "\n", + "a mermaid homage to the dual usage of the WEB file format being translated to a document and programming language.\n", + "\n", + "
\n", " \n", "```mermaid\n", "flowchart LR\n", @@ -489,7 +544,11 @@ ], "source": [ "
\n", - "
a mermaid homage to the dual usage of the WEB file format being translated to a document and programming language.
\n", + "
\n", + "\n", + "a mermaid homage to the dual usage of the WEB file format being translated to a document and programming language.\n", + "\n", + "
\n", " \n", "```mermaid\n", "flowchart LR\n", @@ -511,15 +570,15 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 5, "id": "7d0248b0-d411-4dd3-b495-b8636cf9dc9b", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:51:57.403374Z", - "iopub.status.busy": "2023-02-24T23:51:57.403092Z", - "iopub.status.idle": "2023-02-24T23:51:57.410151Z", - "shell.execute_reply": "2023-02-24T23:51:57.409586Z", - "shell.execute_reply.started": "2023-02-24T23:51:57.403348Z" + "iopub.execute_input": "2023-03-03T03:04:18.699568Z", + "iopub.status.busy": "2023-03-03T03:04:18.699168Z", + "iopub.status.idle": "2023-03-03T03:04:18.705237Z", + "shell.execute_reply": "2023-03-03T03:04:18.704739Z", + "shell.execute_reply.started": "2023-03-03T03:04:18.699552Z" }, "jupyter": { "source_hidden": true @@ -535,8 +594,8 @@ "text/markdown": [ "## reactive `jinja2` templates\n", "\n", - "\n", - "\n", + "\n", + "\n", "\n", "`pidgy` relies on a `midgy` to tangle markdown to code, it does not doing any work on displaying the input markdown. including the templating language is the innovation of `pidgy` that inlines live computation.\n", "\n", @@ -554,8 +613,8 @@ "source": [ "## reactive `jinja2` templates\n", "\n", - "\n", - "\n", + "\n", + "\n", "\n", "`pidgy` relies on a `midgy` to tangle markdown to code, it does not doing any work on displaying the input markdown. including the templating language is the innovation of `pidgy` that inlines live computation.\n", "\n", @@ -565,15 +624,15 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 6, "id": "6d7e9b60-1ec3-4ffd-aad1-1913dcfe622b", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:51:58.402383Z", - "iopub.status.busy": "2023-02-24T23:51:58.401752Z", - "iopub.status.idle": "2023-02-24T23:51:58.410684Z", - "shell.execute_reply": "2023-02-24T23:51:58.410278Z", - "shell.execute_reply.started": "2023-02-24T23:51:58.402347Z" + "iopub.execute_input": "2023-03-03T03:04:18.705924Z", + "iopub.status.busy": "2023-03-03T03:04:18.705745Z", + "iopub.status.idle": "2023-03-03T03:04:18.713849Z", + "shell.execute_reply": "2023-03-03T03:04:18.713204Z", + "shell.execute_reply.started": "2023-03-03T03:04:18.705909Z" }, "jupyter": { "source_hidden": true @@ -669,15 +728,15 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 7, "id": "4bbf7d1e-6c91-40f8-97d5-5b2bf295bb65", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:51:59.042701Z", - "iopub.status.busy": "2023-02-24T23:51:59.042464Z", - "iopub.status.idle": "2023-02-24T23:51:59.055163Z", - "shell.execute_reply": "2023-02-24T23:51:59.054745Z", - "shell.execute_reply.started": "2023-02-24T23:51:59.042682Z" + "iopub.execute_input": "2023-03-03T03:04:18.721674Z", + "iopub.status.busy": "2023-03-03T03:04:18.721470Z", + "iopub.status.idle": "2023-03-03T03:04:18.735782Z", + "shell.execute_reply": "2023-03-03T03:04:18.735086Z", + "shell.execute_reply.started": "2023-03-03T03:04:18.721658Z" }, "jupyter": { "source_hidden": true @@ -691,7 +750,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "757523c5875040caa9aaa0e631e05be5", + "model_id": "f016f5bea3b4435ca354c50cabede4bd", "version_major": 2, "version_minor": 0 }, @@ -785,21 +844,21 @@ }, { "cell_type": "code", - "execution_count": 16, - "id": "f2519914-1eb1-4b02-837b-6143eb4e7267", + "execution_count": 8, + "id": "e12848ff-3409-4bb4-bce9-670109434cad", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:51:59.560340Z", - "iopub.status.busy": "2023-02-24T23:51:59.559325Z", - "iopub.status.idle": "2023-02-24T23:51:59.735349Z", - "shell.execute_reply": "2023-02-24T23:51:59.734984Z", - "shell.execute_reply.started": "2023-02-24T23:51:59.560303Z" + "iopub.execute_input": "2023-03-03T03:04:18.736570Z", + "iopub.status.busy": "2023-03-03T03:04:18.736397Z", + "iopub.status.idle": "2023-03-03T03:04:19.549969Z", + "shell.execute_reply": "2023-03-03T03:04:19.549641Z", + "shell.execute_reply.started": "2023-03-03T03:04:18.736552Z" }, "jupyter": { "source_hidden": true }, "slideshow": { - "slide_type": "subslide" + "slide_type": "slide" }, "tags": [] }, @@ -809,18 +868,33 @@ "text/markdown": [ "### live data in your document\n", "\n", - "demonstrate asynchrony here\n", - "\n", - "
\n", + "
\n", "imports for the pandas matplotlib demo\n", - "
\n", "\n", " import pandas\n", + " from pidgy import get_cell_id\n", + " %matplotlib agg\n", + " \n", + "
\n", "\n", - "including figures and tables \n", + "
\n", + "supporting methods for the interactive demo`\n", "\n", - " df = pandas\n", - " " + " @functools.lru_cache\n", + " def get_gist(x, max=100):\n", + "[gather gist from the github api][gist].\n", + " \n", + " return pandas.read_json(F\"https://api.github.com/users/{x}/gists?per_page={max}\")\n", + " \n", + "[gist]: https://docs.github.com/en/rest/gists?apiVersion=2022-11-28\n", + "\n", + " def tidy_gist(x):\n", + "explode the gist repsonse into a dataframe of gist files\n", + " \n", + " gists = get_gist(x).set_index(\"id\")\n", + " return gists.files.apply(compose_left(dict.values, list)).explode().apply(pandas.Series).join(gists)\n", + " \n", + "
" ], "text/plain": [ "" @@ -833,35 +907,300 @@ "source": [ "### live data in your document\n", "\n", - "demonstrate asynchrony here\n", - "\n", - "
\n", + "
\n", "imports for the pandas matplotlib demo\n", - "
\n", "\n", " import pandas\n", + " from pidgy import get_cell_id\n", + " %matplotlib agg\n", + " \n", + "
\n", + "\n", + "
\n", + "supporting methods for the interactive demo`\n", "\n", - "including figures and tables \n", + " @functools.lru_cache\n", + " def get_gist(x, max=100):\n", + "[gather gist from the github api][gist].\n", + " \n", + " return pandas.read_json(F\"https://api.github.com/users/{x}/gists?per_page={max}\")\n", + " \n", + "[gist]: https://docs.github.com/en/rest/gists?apiVersion=2022-11-28\n", "\n", - " df = pandas\n", - " " + " def tidy_gist(x):\n", + "explode the gist repsonse into a dataframe of gist files\n", + " \n", + " gists = get_gist(x).set_index(\"id\")\n", + " return gists.files.apply(compose_left(dict.values, list)).explode().apply(pandas.Series).join(gists)\n", + " \n", + "
" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 9, + "id": "8262925d-a79e-4eaa-8acd-360da3e45f7d", + "metadata": { + "execution": { + "iopub.execute_input": "2023-03-03T03:04:19.550599Z", + "iopub.status.busy": "2023-03-03T03:04:19.550427Z", + "iopub.status.idle": "2023-03-03T03:04:19.688367Z", + "shell.execute_reply": "2023-03-03T03:04:19.687830Z", + "shell.execute_reply.started": "2023-03-03T03:04:19.550587Z" + }, + "jupyter": { + "source_hidden": true + }, + "slideshow": { + "slide_type": "subslide" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "7d97888f8793458e9b5b1890ed2b0128", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Text(value='tonyfast')" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f2f83d66fd4342359aae8d4f64e1cf69", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='submit', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "#### an application in a cell.\n", + "\n", + "\n", + "\n", + "\n", + "we've found information on 100 github gists, and 121 files, for @tonyfast.\n", + "in this collection, there are 6 different languages included. their most common language is Jupyter Notebook.\n", + "\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
filenametypelanguageraw_urlsizeurlforks_urlcommits_urlnode_idgit_pull_url...filespubliccreated_atupdated_atdescriptioncommentsusercomments_urlownertruncated
id
89fd5090a964b565e2575e50fd51744fnox-magic.ipynbtext/plainJupyter Notebookhttps://gist.githubusercontent.com/tonyfast/89...8072https://api.github.com/gists/89fd5090a964b565e...https://api.github.com/gists/89fd5090a964b565e...https://api.github.com/gists/89fd5090a964b565e...MDQ6R2lzdDg5ZmQ1MDkwYTk2NGI1NjVlMjU3NWU1MGZkNT...https://gist.github.com/89fd5090a964b565e2575e......{'nox-magic.ipynb': {'filename': 'nox-magic.ip...True2021-05-01 03:02:46+00:002021-05-01 03:02:46+00:000NaNhttps://api.github.com/gists/89fd5090a964b565e...{'login': 'tonyfast', 'id': 4236275, 'node_id'...False
3440a5b4c19a257d6164fff93fbef154magics.ipynbtext/plainJupyter Notebookhttps://gist.githubusercontent.com/tonyfast/34...12759https://api.github.com/gists/3440a5b4c19a257d6...https://api.github.com/gists/3440a5b4c19a257d6...https://api.github.com/gists/3440a5b4c19a257d6...MDQ6R2lzdDM0NDBhNWI0YzE5YTI1N2Q2MTY0ZmZmOTNmYm...https://gist.github.com/3440a5b4c19a257d6164ff......{'magics.ipynb': {'filename': 'magics.ipynb', ...True2021-05-28 16:15:20+00:002021-05-28 20:48:01+00:000NaNhttps://api.github.com/gists/3440a5b4c19a257d6...{'login': 'tonyfast', 'id': 4236275, 'node_id'...False
\n", + "

2 rows × 22 columns

\n", + "
\n", + "\n", + " display(\n", + " _github_user := Text(\"tonyfast\"), button := Button(description=\"submit\"))\n", + " button.on_click(lambda x, id=get_cell_id(): print(id) or shell.weave.displays[id].update())\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Jupyter NotebookPythonTextMarkdownHTMLJSON
ct84159821
\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#### an application in a cell.\n", + "\n", + "{% set gists = tidy_gist(_github_user.value) %}\n", + "{% set lang = gists.language.dropna().value_counts() %}\n", + "\n", + "we've found information on {{gists.index.unique().shape[0]}} github gists, and {{len(gists)}} files, for @{{_github_user.value}}.\n", + "in this collection, there are {{len(lang)}} different languages included. their most common language is {{lang.index[0]}}.\n", + "\n", + "{{gists.sample(2)}}\n", + "\n", + " display(\n", + " _github_user := Text(\"tonyfast\"), button := Button(description=\"submit\"))\n", + " button.on_click(lambda x, id=get_cell_id(): print(id) or shell.weave.displays[id].update())\n", + "{{lang.to_frame(\"ct\").T}}" + ] + }, + { + "cell_type": "code", + "execution_count": 10, "id": "18342220-1c06-4e36-8c48-f3d23f8552d2", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:52:00.494901Z", - "iopub.status.busy": "2023-02-24T23:52:00.494513Z", - "iopub.status.idle": "2023-02-24T23:52:00.504524Z", - "shell.execute_reply": "2023-02-24T23:52:00.504120Z", - "shell.execute_reply.started": "2023-02-24T23:52:00.494869Z" + "iopub.execute_input": "2023-03-03T03:04:19.689422Z", + "iopub.status.busy": "2023-03-03T03:04:19.689080Z", + "iopub.status.idle": "2023-03-03T03:04:19.699497Z", + "shell.execute_reply": "2023-03-03T03:04:19.698825Z", + "shell.execute_reply.started": "2023-03-03T03:04:19.689398Z" }, "jupyter": { "source_hidden": true }, + "slideshow": { + "slide_type": "fragment" + }, "tags": [] }, "outputs": [ @@ -894,15 +1233,15 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 11, "id": "d8409c09-f71d-4186-8e93-6921e2970d74", "metadata": { "execution": { - "iopub.execute_input": "2023-02-24T23:52:01.351014Z", - "iopub.status.busy": "2023-02-24T23:52:01.350727Z", - "iopub.status.idle": "2023-02-24T23:52:01.360031Z", - "shell.execute_reply": "2023-02-24T23:52:01.359674Z", - "shell.execute_reply.started": "2023-02-24T23:52:01.350993Z" + "iopub.execute_input": "2023-03-03T03:04:19.700577Z", + "iopub.status.busy": "2023-03-03T03:04:19.700380Z", + "iopub.status.idle": "2023-03-03T03:04:19.715961Z", + "shell.execute_reply": "2023-03-03T03:04:19.715268Z", + "shell.execute_reply.started": "2023-03-03T03:04:19.700559Z" }, "jupyter": { "source_hidden": true @@ -979,6 +1318,18 @@ }, "outputs": [], "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "28254214-6352-4ba2-ad39-84dbd34e4b2f", + "metadata": { + "jupyter": { + "source_hidden": true + } + }, + "outputs": [], + "source": [] } ], "metadata": { @@ -1002,73 +1353,71 @@ "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { - "14e4caff16964ff1b39945b4ed44841d": { + "049278abfa294c0db4a5587c1f0388cc": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", - "model_name": "CheckboxStyleModel", - "state": { - "description_width": "" - } - }, - "20156e7f88084efea172b481f55163cc": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "2.0.0", - "model_name": "CheckboxStyleModel", - "state": { - "description_width": "" - } - }, - "49f16598e73f428ca656ac2990dd3b27": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "2.0.0", - "model_name": "CheckboxStyleModel", + "model_name": "SliderStyleModel", "state": { "description_width": "" } }, - "4d4666ea9c3345019c1046a767c5d875": { + "19a390e5943c408bb0a2fd03d819ac60": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {} }, - "757523c5875040caa9aaa0e631e05be5": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "2.0.0", - "model_name": "IntSliderModel", - "state": { - "behavior": "drag-tap", - "description": "🍪", - "layout": "IPY_MODEL_cdab9dfb667941b9a6af9e0032903a00", - "style": "IPY_MODEL_cd48e782e0c14a39bdf49bcea8a6b692", - "value": 3 - } - }, - "a8d6210c36044f2a91662ca5b21f1c3c": { + "624f5c44a24a4fdb86ca8530e9766ec4": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {} }, - "ae276d98c5c14a9e85e83fd840c70cfb": { + "7001f7f85ef8452882c868d634f91832": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {} }, - "bc3cb1e3aaef4a6096cf8c02d86a5b6b": { - "model_module": "@jupyter-widgets/base", + "7d97888f8793458e9b5b1890ed2b0128": { + "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", - "model_name": "LayoutModel", - "state": {} + "model_name": "TextModel", + "state": { + "layout": "IPY_MODEL_624f5c44a24a4fdb86ca8530e9766ec4", + "style": "IPY_MODEL_fdbe474d5faf4f2c8e1a0a04125a932e", + "value": "tonyfast" + } }, - "ca4275e522244ab29c264599101067c8": { - "model_module": "@jupyter-widgets/base", + "8cd9ea1510f349b4b433f238581ae1bd": { + "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", - "model_name": "LayoutModel", - "state": {} + "model_name": "ButtonStyleModel", + "state": { + "font_family": null, + "font_size": null, + "font_style": null, + "font_variant": null, + "font_weight": null, + "text_color": null, + "text_decoration": null + } + }, + "a59df83a6d58485bb5d8618256e25abc": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "IntSliderModel", + "state": { + "behavior": "drag-tap", + "description": "show more languages", + "layout": "IPY_MODEL_19a390e5943c408bb0a2fd03d819ac60", + "max": 6, + "min": 1, + "style": "IPY_MODEL_bceb7f3a84fc489ba4019921fcdc9df7", + "value": 6 + } }, - "cd48e782e0c14a39bdf49bcea8a6b692": { + "bceb7f3a84fc489ba4019921fcdc9df7": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "SliderStyleModel", @@ -1076,38 +1425,43 @@ "description_width": "" } }, - "cdab9dfb667941b9a6af9e0032903a00": { + "e7ac690d2a12492ab162dc9503938061": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": {} }, - "d1ab4844426f4da0be2d1447c0c381d0": { + "f016f5bea3b4435ca354c50cabede4bd": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", - "model_name": "CheckboxStyleModel", + "model_name": "IntSliderModel", "state": { - "description_width": "" + "behavior": "drag-tap", + "description": "🍪", + "layout": "IPY_MODEL_7001f7f85ef8452882c868d634f91832", + "style": "IPY_MODEL_049278abfa294c0db4a5587c1f0388cc", + "value": 3 } }, - "da04dd6c660f427a90d35e315256e2e9": { + "f2f83d66fd4342359aae8d4f64e1cf69": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", - "model_name": "CheckboxModel", + "model_name": "ButtonModel", "state": { - "description": "show more languages", - "disabled": false, - "layout": "IPY_MODEL_a8d6210c36044f2a91662ca5b21f1c3c", - "style": "IPY_MODEL_efd0faeff0a449e28700f24141d55b55", - "value": false + "description": "submit", + "layout": "IPY_MODEL_e7ac690d2a12492ab162dc9503938061", + "style": "IPY_MODEL_8cd9ea1510f349b4b433f238581ae1bd", + "tooltip": null } }, - "efd0faeff0a449e28700f24141d55b55": { + "fdbe474d5faf4f2c8e1a0a04125a932e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", - "model_name": "CheckboxStyleModel", + "model_name": "TextStyleModel", "state": { - "description_width": "" + "description_width": "", + "font_size": null, + "text_color": null } } }, diff --git a/src/pidgy/displays.py b/src/pidgy/displays.py index b3d948f4..f6a071ba 100644 --- a/src/pidgy/displays.py +++ b/src/pidgy/displays.py @@ -144,6 +144,10 @@ async def aupdate(self): if self.display_handle: self.display_handle.value = await self.arender() + def update(self): + if self.display_handle: + self.display_handle.value = self.render() + def _ipython_display_(self): if self.display_handle is None: self.display_handle = self.display_object("") diff --git a/src/pidgy/weave.py b/src/pidgy/weave.py index bc6edca5..7ad98a81 100644 --- a/src/pidgy/weave.py +++ b/src/pidgy/weave.py @@ -63,13 +63,12 @@ async def aweave_cell(self, body): markdown_renderer=self.markdown_renderer, use_async=self.use_async, ) - + return self.display_no_template(body) - + def display_no_template(self, body): return self.template_cls.display_cls(body) - def filter_meta_tokens(self, body): if self.shell.has_trait("current_execution") and self.shell.current_execution.tokens: for token in self.shell.current_execution.tokens: @@ -159,8 +158,9 @@ def link_widgets(self): displays_by_key = self.get_vars() olds = list() for key, displays in displays_by_key.items(): + if key.startswith("_"): + continue value = self.get_value(key) - if is_widget(value): if self.widgets.setdefault(key, value) is not value: olds.append(self.widgets[key]) @@ -176,7 +176,7 @@ def weave(self, body): display = self.weave_cell(body) if self.template: id = self.get_id() - self.displays[id] = display + self.displays[id] = display return display def post_run_cell(self, result): @@ -211,30 +211,50 @@ def pre_execute(self): self.del_displays(metadata) vars = set() - for id, disp in self.displays.items(): + for disp in self.displays.values(): if disp.vars: vars.update(disp.vars) # collect the state of any reactive or tracked variables before execution self.prior.update(zip(vars, map(self.get_value, vars))) - def post_execute(self, force=False): - if force or (self.enabled and self.reactive): - changed = set() - - if self.reactive: - for k, v in self.prior.items(): - y = self.get_value(k) - if y is not v: - changed.add(k) + def get_changed_vars(self): + changed = set() - for disp in self.displays.values(): - if changed.intersection(disp.vars): - ensure_future(disp.aupdate()) + for k, v in self.prior.items(): + y = self.get_value(k) + if y is not v: + changed.add(k) + return changed + def post_execute(self): + if self.enabled and self.reactive: + self.update() self.link_widgets() - def update(self): - self.post_execute(True) + def update(self, *id, force=False, changed: set = None): + """update the displays + + id: + specific display ids to update + force: + force all the display to be updated + changed: + a set of variables changed since the last rendering.""" + if id: + get_ipython().log.error(id) + for i in id: + ensure_future(self.displays[i].aupdate()) + else: + if force: + changed = set(self.prior) + if changed is None: + changed = self.get_changed_vars() + if changed: + for i, disp in self.displays.items(): + if not force and id and i not in id: + continue + if changed is not None and changed.intersection(disp.vars): + ensure_future(disp.aupdate()) def _add_weave_trait(shell):