Skip to content

Commit

Permalink
update the smaple figure
Browse files Browse the repository at this point in the history
  • Loading branch information
Dou Du committed Jun 3, 2024
1 parent eab68bc commit a528bee
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
82 changes: 54 additions & 28 deletions example/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,7 @@
"execution_count": 1,
"id": "5df2c405",
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "File not found: /home/taylor/widget-code-input-to-anywidget/widget-code-input/widget_code_input/static/index.js",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mwidget_code_input\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m CodeInputWidget\n\u001b[1;32m 2\u001b[0m \u001b[38;5;66;03m# import importlib\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m# importlib.reload(code_input_widget)\u001b[39;00m\n\u001b[1;32m 5\u001b[0m w \u001b[38;5;241m=\u001b[39m CodeInputWidget(\n\u001b[1;32m 6\u001b[0m function_name \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmy_function\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 7\u001b[0m function_parameters \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma, b\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 12\u001b[0m code_theme\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbasicLight\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 13\u001b[0m )\n",
"File \u001b[0;32m~/widget-code-input-to-anywidget/widget-code-input/widget_code_input/__init__.py:7\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m#!/usr/bin/env python\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;66;03m# coding: utf-8\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \n\u001b[1;32m 4\u001b[0m \u001b[38;5;66;03m# Copyright (c) Dou Du.\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;66;03m# Distributed under the terms of the Modified BSD License.\u001b[39;00m\n\u001b[0;32m----> 7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mCodeInputWidget\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_version\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m __version__, version_info\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_jupyter_labextension_paths\u001b[39m():\n",
"File \u001b[0;32m~/widget-code-input-to-anywidget/widget-code-input/widget_code_input/CodeInputWidget.py:24\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[1;32m 12\u001b[0m CodeValidationError,\n\u001b[1;32m 13\u001b[0m build_function,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 17\u001b[0m format_generic_error_msg,\n\u001b[1;32m 18\u001b[0m )\n\u001b[1;32m 21\u001b[0m bundler_output_dir \u001b[38;5;241m=\u001b[39m pathlib\u001b[38;5;241m.\u001b[39mPath(os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mdirname(os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mabspath(\u001b[38;5;18m__file__\u001b[39m))) \u001b[38;5;241m/\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m./static\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m---> 24\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mCodeInputWidget\u001b[39;00m(anywidget\u001b[38;5;241m.\u001b[39mAnyWidget):\n\u001b[1;32m 25\u001b[0m widget_instance_count\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m \u001b[38;5;66;03m# counter to keep track of number of widget instances in use\u001b[39;00m\n\u001b[1;32m 27\u001b[0m function_name \u001b[38;5;241m=\u001b[39m Unicode(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mexample\u001b[39m\u001b[38;5;124m'\u001b[39m)\u001b[38;5;241m.\u001b[39mtag(sync\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
"File \u001b[0;32m~/miniconda3/envs/scwidgets-dev/lib/python3.11/site-packages/traitlets/traitlets.py:967\u001b[0m, in \u001b[0;36mMetaHasDescriptors.__new__\u001b[0;34m(mcls, name, bases, classdict)\u001b[0m\n\u001b[1;32m 964\u001b[0m classdict[k] \u001b[38;5;241m=\u001b[39m v()\n\u001b[1;32m 965\u001b[0m \u001b[38;5;66;03m# ----------------------------------------------------------------\u001b[39;00m\n\u001b[0;32m--> 967\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__new__\u001b[39m(mcls, name, bases, classdict)\n",
"File \u001b[0;32m~/miniconda3/envs/scwidgets-dev/lib/python3.11/site-packages/anywidget/widget.py:66\u001b[0m, in \u001b[0;36mAnyWidget.__init_subclass__\u001b[0;34m(cls, **kwargs)\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m__init_subclass__(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 64\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m key \u001b[38;5;129;01min\u001b[39;00m (_ESM_KEY, _CSS_KEY) \u001b[38;5;241m&\u001b[39m \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__dict__\u001b[39m\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 65\u001b[0m \u001b[38;5;66;03m# TODO: Upgrate to := when we drop Python 3.7\u001b[39;00m\n\u001b[0;32m---> 66\u001b[0m file_contents \u001b[38;5;241m=\u001b[39m try_file_contents(\u001b[38;5;28mgetattr\u001b[39m(\u001b[38;5;28mcls\u001b[39m, key))\n\u001b[1;32m 67\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m file_contents:\n\u001b[1;32m 68\u001b[0m \u001b[38;5;28msetattr\u001b[39m(\u001b[38;5;28mcls\u001b[39m, key, file_contents)\n",
"File \u001b[0;32m~/miniconda3/envs/scwidgets-dev/lib/python3.11/site-packages/anywidget/_util.py:258\u001b[0m, in \u001b[0;36mtry_file_contents\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 256\u001b[0m path \u001b[38;5;241m=\u001b[39m maybe_path\n\u001b[1;32m 257\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m path\u001b[38;5;241m.\u001b[39mis_file():\n\u001b[0;32m--> 258\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mFileNotFoundError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFile not found: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpath\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 259\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m FileContents(\n\u001b[1;32m 260\u001b[0m path\u001b[38;5;241m=\u001b[39mpath,\n\u001b[1;32m 261\u001b[0m start_thread\u001b[38;5;241m=\u001b[39m_should_start_thread(path),\n\u001b[1;32m 262\u001b[0m )\n",
"\u001b[0;31mFileNotFoundError\u001b[0m: File not found: /home/taylor/widget-code-input-to-anywidget/widget-code-input/widget_code_input/static/index.js"
]
}
],
"outputs": [],
"source": [
"from widget_code_input import CodeInputWidget\n",
"# import importlib\n",
Expand All @@ -42,17 +25,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "e74c9c9e",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a9bc0492a35a4019b4646de369c60da8",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"CodeInputWidget(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "4d389a14",
"metadata": {},
"outputs": [],
Expand All @@ -62,17 +61,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "2fc2b3ed",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_function(1, 2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "601edb7d",
"metadata": {},
"outputs": [],
Expand All @@ -82,7 +92,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "e90010bd",
"metadata": {},
"outputs": [],
Expand All @@ -92,10 +102,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "75900629",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "39e3b4757918408991f06b8777390f31",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"CodeInputWidget(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w2 = CodeInputWidget(\n",
" function_name = \"my_function\",\n",
Expand Down Expand Up @@ -126,7 +152,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
Binary file modified test/widget-sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a528bee

Please sign in to comment.