Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ jobs:
run: pixi run pre-commit-all
- name: Run unit tests
run: pixi run test
- name: Run example notebook
run: |
pixi run serve-jupyter nbconvert \
--to notebook \
--execute \
--ExecutePreprocessor.store_widget_state=False \
--output "${PWD}/out.ipynb" \
examples/widgets.ipynb

# Widgets did render successufully as mime bundle
grep 'application/vnd.jupyter.ywidget-view+json' "${PWD}/out.ipynb"
3 changes: 2 additions & 1 deletion R/comm.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ mime_bundle.CommWidget <- function(x, mimetypes = mime_types(x), ...) {
model_id = x$comm_id()
)
),
metadata = list()
# Serialize as dict, not list
metadata = structure(list(), names = character(0))
)
}

Expand Down
149 changes: 149 additions & 0 deletions examples/widgets.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "8ea1654d-6607-46dc-ad2f-60d58b451741",
"metadata": {},
"outputs": [],
"source": [
"# devtools::load_all(\".\")\n",
"\n",
"library(\"ywidget\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc523884-6cdd-4191-84ea-cb2fafda18c2",
"metadata": {},
"outputs": [],
"source": [
"IntSlider <- make_comm_widget(\n",
" \"IntSlider\",\n",
" value = 50L,\n",
" min = 0L,\n",
" max = 100L,\n",
" step = 1L\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f0df5ce5-779b-4b8c-b338-3e5cab824318",
"metadata": {},
"outputs": [],
"source": [
"s <- IntSlider$new()\n",
"s"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "359d9faa-7400-4548-b03e-641edc373b19",
"metadata": {},
"outputs": [],
"source": [
"s$value"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "51225b68-1855-4557-9825-d76270e07468",
"metadata": {},
"outputs": [],
"source": [
"s$value = 0"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ce581d9-2932-40bd-92f0-8b7ab5e64610",
"metadata": {},
"outputs": [],
"source": [
"s2 <- IntSlider$new()\n",
"s2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "163e7eb1-400b-4e54-9ca4-bb8186259c64",
"metadata": {},
"outputs": [],
"source": [
"s"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "54f82252-6b3d-402f-8525-b4980ef4e5a8",
"metadata": {},
"outputs": [],
"source": [
"Textarea <- make_comm_widget(\n",
" \"Textarea\",\n",
" value = \"\",\n",
" rows = 0L,\n",
" disabled = FALSE,\n",
" continuous_update = TRUE\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7c327b3f-9f81-4a94-a013-760b3ee9bc93",
"metadata": {},
"outputs": [],
"source": [
"t <- Textarea$new()\n",
"t"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8fa605f-e8f1-403a-a429-21ede9dfd29c",
"metadata": {},
"outputs": [],
"source": [
"t$value"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "237427fd-6d51-4d8b-a85c-27a4a269a4d6",
"metadata": {},
"outputs": [],
"source": [
"t$value <- \"Hello world!\""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "R 4.4.3 (xr)",
"language": "R",
"name": "xr"
},
"language_info": {
"codemirror_mode": "",
"file_extension": ".R",
"mimetype": "text/x-R",
"name": "R",
"nbconvert_exporter": "",
"pygments_lexer": "r",
"version": "4.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
33 changes: 23 additions & 10 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ typos = "*"
pre-commit = "*"
jupyterlab = ">=4"
jupyterlab-kernelspy = "*"
yjs-widgets = "*"
yjs-widgets-collection = "*"

[feature.dev.tasks.install-ywidget]
cmd = "R CMD INSTALL ."

[feature.dev.tasks.serve-jupyter]
cmd = "jupyter"
depends-on = ["install-ywidget"]

[feature.dev.tasks]
# Document
Expand Down