diff --git a/example/example.ipynb b/example/example.ipynb index f2c9da0..820412a 100644 --- a/example/example.ipynb +++ b/example/example.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "5df2c405", "metadata": {}, "outputs": [], @@ -25,33 +25,19 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "e74c9c9e", - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "80b8268cbfe0416494f266f6f8a19aa1", - "version_major": 2, - "version_minor": 1 - }, - "text/plain": [ - "WidgetCodeInput(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], + "metadata": { + "scrolled": true + }, + "outputs": [], "source": [ "w" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "4d389a14", "metadata": {}, "outputs": [], @@ -61,28 +47,17 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "2fc2b3ed", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_function(1, 2)" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "e90010bd", "metadata": {}, "outputs": [], @@ -92,26 +67,10 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "75900629", "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9238263cacc04a728e878c13d8fac749", - "version_major": 2, - "version_minor": 1 - }, - "text/plain": [ - "WidgetCodeInput(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "w2 = WidgetCodeInput(\n", " function_name = \"my_function\",\n", @@ -142,7 +101,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.10.15" } }, "nbformat": 4, diff --git a/js/widget.js b/js/widget.js index aed60ee..0a4bafa 100644 --- a/js/widget.js +++ b/js/widget.js @@ -13,20 +13,27 @@ import { nord } from 'cm6-theme-nord' import { solarizedLight } from 'cm6-theme-solarized-light' import { basicLight } from 'cm6-theme-basic-light' import './widget.css'; + +function generateRandomString(length) { + let result = ""; + while (result.length < length) { + result += Math.random().toString(36).substring(2); + } + return result.substring(0, length); + } + + export default{ initialize({ model }) { // /* (optional) model initialization logic */ }, - /** @param {{ model: DOMWidgetModel, el: HTMLElement }} context */ render({model,el}) { - - - var unique_funcbody_id = model.get('widget_instance_count_trait') + var unique_funcbody_id = generateRandomString(6) model.attributes={function_body_id:unique_funcbody_id}