Skip to content

Commit c0969a9

Browse files
authored
Add example notebook (#1)
1 parent 1c6d3d1 commit c0969a9

5 files changed

Lines changed: 194 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@ jobs:
3131
run: pixi run pre-commit-all
3232
- name: Run unit tests
3333
run: pixi run test
34+
- name: Run example notebook
35+
run: |
36+
pixi run serve-jupyter nbconvert \
37+
--to notebook \
38+
--execute \
39+
--ExecutePreprocessor.store_widget_state=False \
40+
--output "${PWD}/out.ipynb" \
41+
examples/widgets.ipynb
42+
43+
# Widgets did render successufully as mime bundle
44+
grep 'application/vnd.jupyter.ywidget-view+json' "${PWD}/out.ipynb"

R/comm.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ mime_bundle.CommWidget <- function(x, mimetypes = mime_types(x), ...) {
221221
model_id = x$comm_id()
222222
)
223223
),
224-
metadata = list()
224+
# Serialize as dict, not list
225+
metadata = structure(list(), names = character(0))
225226
)
226227
}
227228

examples/widgets.ipynb

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "8ea1654d-6607-46dc-ad2f-60d58b451741",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"# devtools::load_all(\".\")\n",
11+
"\n",
12+
"library(\"ywidget\")"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": null,
18+
"id": "fc523884-6cdd-4191-84ea-cb2fafda18c2",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"IntSlider <- make_comm_widget(\n",
23+
" \"IntSlider\",\n",
24+
" value = 50L,\n",
25+
" min = 0L,\n",
26+
" max = 100L,\n",
27+
" step = 1L\n",
28+
")"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"id": "f0df5ce5-779b-4b8c-b338-3e5cab824318",
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"s <- IntSlider$new()\n",
39+
"s"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"id": "359d9faa-7400-4548-b03e-641edc373b19",
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"s$value"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"id": "51225b68-1855-4557-9825-d76270e07468",
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"s$value = 0"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"id": "1ce581d9-2932-40bd-92f0-8b7ab5e64610",
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"s2 <- IntSlider$new()\n",
70+
"s2"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": null,
76+
"id": "163e7eb1-400b-4e54-9ca4-bb8186259c64",
77+
"metadata": {},
78+
"outputs": [],
79+
"source": [
80+
"s"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"id": "54f82252-6b3d-402f-8525-b4980ef4e5a8",
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"Textarea <- make_comm_widget(\n",
91+
" \"Textarea\",\n",
92+
" value = \"\",\n",
93+
" rows = 0L,\n",
94+
" disabled = FALSE,\n",
95+
" continuous_update = TRUE\n",
96+
")"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": null,
102+
"id": "7c327b3f-9f81-4a94-a013-760b3ee9bc93",
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"t <- Textarea$new()\n",
107+
"t"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": null,
113+
"id": "b8fa605f-e8f1-403a-a429-21ede9dfd29c",
114+
"metadata": {},
115+
"outputs": [],
116+
"source": [
117+
"t$value"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"id": "237427fd-6d51-4d8b-a85c-27a4a269a4d6",
124+
"metadata": {},
125+
"outputs": [],
126+
"source": [
127+
"t$value <- \"Hello world!\""
128+
]
129+
}
130+
],
131+
"metadata": {
132+
"kernelspec": {
133+
"display_name": "R 4.4.3 (xr)",
134+
"language": "R",
135+
"name": "xr"
136+
},
137+
"language_info": {
138+
"codemirror_mode": "",
139+
"file_extension": ".R",
140+
"mimetype": "text/x-R",
141+
"name": "R",
142+
"nbconvert_exporter": "",
143+
"pygments_lexer": "r",
144+
"version": "4.4.3"
145+
}
146+
},
147+
"nbformat": 4,
148+
"nbformat_minor": 5
149+
}

pixi.lock

Lines changed: 23 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ typos = "*"
3030
pre-commit = "*"
3131
jupyterlab = ">=4"
3232
jupyterlab-kernelspy = "*"
33+
yjs-widgets = "*"
34+
yjs-widgets-collection = "*"
35+
36+
[feature.dev.tasks.install-ywidget]
37+
cmd = "R CMD INSTALL ."
38+
39+
[feature.dev.tasks.serve-jupyter]
40+
cmd = "jupyter"
41+
depends-on = ["install-ywidget"]
3342

3443
[feature.dev.tasks]
3544
# Document

0 commit comments

Comments
 (0)