Reactive widget models whose state is synchronised through Conflict-free Replicated
Data Type (CRDT) via the yrs package.
- R >= 4.1
yr,R6- An xeus-r Jupyter kernel (provides
hera) and a frontend that speaks theywidgetcomm protocol, e.g. JupyterLab withyjs-widgets.
make_comm_widget() defines an R6 class whose named attributes are backed by a
shared ydoc. Constructing an instance opens a Jupyter comm and keeps the
attributes in sync with the connected frontend.
library(ywidget)
# Define a widget class with two synced attributes.
Counter <- make_comm_widget("Counter", label = "", count = 0L)
# Constructing opens the comm and starts syncing. Run this in an xeus-r kernel.
w <- Counter$new(label = "clicks")
# Attributes are active bindings: read and write them directly.
w$count
w$count <- w$count + 1L
# React to changes coming from the frontend.
w$connect(count = function(value) {
message("count is now ", value)
})
Writes to an attribute update the ydoc and propagate to the frontend; remote
changes update the attribute and fire the callbacks registered with
$connect().
- yr: the R bindings to the Rust yrs CRDT library.
- yjs-widgets A core CRDT library to build widget frontends.
- ypywidgets A similar Python core widget library from which this project is inspired.