1
1
{
2
- "metadata" : {
3
- "kernelspec" : {
4
- "name" : " python" ,
5
- "display_name" : " Python (Pyodide)" ,
6
- "language" : " python"
7
- },
8
- "language_info" : {
9
- "codemirror_mode" : {
10
- "name" : " python" ,
11
- "version" : 3
12
- },
13
- "file_extension" : " .py" ,
14
- "mimetype" : " text/x-python" ,
15
- "name" : " python" ,
16
- "nbconvert_exporter" : " python" ,
17
- "pygments_lexer" : " ipython3" ,
18
- "version" : " 3.8"
19
- }
20
- },
21
- "nbformat_minor" : 4 ,
22
- "nbformat" : 4 ,
23
2
"cells" : [
24
3
{
25
4
"cell_type" : " code" ,
26
- "source " : " %pip install anywidget " ,
5
+ "execution_count " : null ,
27
6
"metadata" : {
28
7
"trusted" : true
29
8
},
30
9
"outputs" : [],
31
- "execution_count" : null
10
+ "source" : [
11
+ " %pip install anywidget"
12
+ ]
32
13
},
33
14
{
34
15
"cell_type" : " code" ,
35
- "source " : " import anywidget \n import traitlets \n\n class CounterWidget(anywidget.AnyWidget): \n _esm = \"\"\"\n function render({ model, el }) { \n let getCount = () => model.get( \" count \" ); \n let button = document.createElement( \" button \" ); \n button.classList.add( \" counter-button \" ); \n button.innerHTML = `count is ${getCount()}`; \n button.addEventListener( \" click \" , () => { \n model.set( \" count \" , getCount() + 1); \n model.save_changes(); \n }); \n model.on( \" change:count \" , () => { \n button.innerHTML = `count is ${getCount()}`; \n }); \n el.appendChild(button); \n } \n\t export default { render }; \n \"\"\"\n _css= \"\"\"\n .counter-button { background-color: #ea580c; } \n .counter-button:hover { background-color: #9a3412; } \n \"\"\"\n count = traitlets.Int(0).tag(sync=True) \n\n counter = CounterWidget() \n counter.count = 42 \n counter " ,
16
+ "execution_count " : null ,
36
17
"metadata" : {
37
18
"trusted" : true
38
19
},
39
20
"outputs" : [],
40
- "execution_count" : null
21
+ "source" : [
22
+ " import anywidget\n " ,
23
+ " import traitlets\n " ,
24
+ " \n " ,
25
+ " class CounterWidget(anywidget.AnyWidget):\n " ,
26
+ " _esm = \"\"\"\n " ,
27
+ " function render({ model, el }) {\n " ,
28
+ " let getCount = () => model.get(\" count\" );\n " ,
29
+ " let button = document.createElement(\" button\" );\n " ,
30
+ " button.classList.add(\" counter-button\" );\n " ,
31
+ " button.innerHTML = `count is ${getCount()}`;\n " ,
32
+ " button.addEventListener(\" click\" , () => {\n " ,
33
+ " model.set(\" count\" , getCount() + 1);\n " ,
34
+ " model.save_changes();\n " ,
35
+ " });\n " ,
36
+ " model.on(\" change:count\" , () => {\n " ,
37
+ " button.innerHTML = `count is ${getCount()}`;\n " ,
38
+ " });\n " ,
39
+ " el.appendChild(button);\n " ,
40
+ " }\n " ,
41
+ " \t export default { render };\n " ,
42
+ " \"\"\"\n " ,
43
+ " _css=\"\"\"\n " ,
44
+ " .counter-button { background-color: #ea580c; }\n " ,
45
+ " .counter-button:hover { background-color: #9a3412; }\n " ,
46
+ " \"\"\"\n " ,
47
+ " count = traitlets.Int(0).tag(sync=True)\n " ,
48
+ " \n " ,
49
+ " counter = CounterWidget()\n " ,
50
+ " counter.count = 42\n " ,
51
+ " counter"
52
+ ]
41
53
},
42
54
{
43
55
"cell_type" : " code" ,
44
- "source " : " " ,
56
+ "execution_count " : null ,
45
57
"metadata" : {
46
58
"trusted" : true
47
59
},
48
60
"outputs" : [],
49
- "execution_count" : null
61
+ "source" : [
62
+ " from pathlib import Path\n " ,
63
+ " \n " ,
64
+ " class CounterWidget(anywidget.AnyWidget):\n " ,
65
+ " _esm = Path('/drive/index.js')\n " ,
66
+ " _css= Path('/drive/index.css')\n " ,
67
+ " count = traitlets.Int(0).tag(sync=True)\n " ,
68
+ " \n " ,
69
+ " counter = CounterWidget()\n " ,
70
+ " counter.count = 42\n " ,
71
+ " counter"
72
+ ]
50
73
}
51
- ]
52
- }
74
+ ],
75
+ "metadata" : {
76
+ "kernelspec" : {
77
+ "display_name" : " Python (Pyodide)" ,
78
+ "language" : " python" ,
79
+ "name" : " python"
80
+ },
81
+ "language_info" : {
82
+ "codemirror_mode" : {
83
+ "name" : " python" ,
84
+ "version" : 3
85
+ },
86
+ "file_extension" : " .py" ,
87
+ "mimetype" : " text/x-python" ,
88
+ "name" : " python" ,
89
+ "nbconvert_exporter" : " python" ,
90
+ "pygments_lexer" : " ipython3" ,
91
+ "version" : " 3.8"
92
+ }
93
+ },
94
+ "nbformat" : 4 ,
95
+ "nbformat_minor" : 4
96
+ }
0 commit comments