From d58cf7ea39cc9c4fddb48e772edc93bbbac71faf Mon Sep 17 00:00:00 2001 From: tannevaled Date: Sat, 14 Nov 2026 22:48:41 +0100 Subject: [PATCH] playground v0.13.0 and v0.14.0: R cells run, editor minimap and annotations Bump playground to v0.14.0 (toolkit v0.375.0), replace notebooks/5-r.md with the running-R example, and update the playground, notebook and "In your browser" texts. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 2 +- hugo.toml | 6 ++--- layouts/index.html | 2 +- playground/go.mod | 7 +++--- playground/go.sum | 14 ++++++----- playground/notebooks/5-r.md | 47 ++++++++++++++++++++++--------------- 6 files changed, 45 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 62133fe..c5163ff 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ and the fleet's [landing kit](https://github.com/go-fleettools/landingkit) (a Hugo module pinned in `go.mod`). - **[/playground/](https://go-notebook.github.io/playground/)**: notebooks - in the browser, Go and Ruby cells, run in WebAssembly with no server. The + in the browser, Go, Ruby and R cells, run in WebAssembly with no server. The deploy workflow builds it with [go-notebook/playground](https://github.com/go-notebook/playground)'s `cmd/build`, at the version `playground/go.mod` pins, from the notebooks in diff --git a/hugo.toml b/hugo.toml index b0531cf..1f4a9a8 100644 --- a/hugo.toml +++ b/hugo.toml @@ -31,7 +31,7 @@ disableKinds = ['taxonomy', 'term', 'rss', 'sitemap', '404'] title = "Go and Ruby cells, and what they printed" [[params.hero.cards]] title = "Try it in your browser" - text = "The playground runs notebooks, Go and Ruby cells, in WebAssembly in the tab: edit a cell, press Ctrl+Enter, see the result." + text = "The playground runs notebooks, Go, Ruby and R cells, in WebAssembly in the tab: edit a cell, press Ctrl+Enter, see the result." href = "/playground/" more = "Open the playground" @@ -41,12 +41,12 @@ disableKinds = ['taxonomy', 'term', 'rss', 'sitemap', '404'] name = "notebook" kind = "kernel · command" href = "https://github.com/go-notebook/notebook" - blurb = "The kernel, the notebook command (run, html, watch, serve, irb) and the HTML export: format parses the Markdown, analysis builds the dependency graph from the syntax, gen writes the Go program, kernel compiles and drives it through runtime and keeps results and values, export writes the page. Ruby cells (```ruby) run on rbgo, a Ruby written in Go, with the go-scikit bindings (Stats, Special, Optimize, Integrate, DataFrame, Plot, NDArray), and share their variables with the Go cells. --timeout and --memory stop a runaway cell in either language. notebook irb is the same Ruby as an interactive session, as irb: => inspect after each input, _, multi-line input decided by rbgo's parser, Tab completion and history in a pure-Go line editor (go-ruby-reline), each input in a worker that --timeout, --memory or Ctrl-C can stop without losing the prompt, and --save to keep the session as a notebook. More → Julia cells (```julia) are parsed with go-embedded-julia's parser and checked: syntax errors at their line with julia's message, names in the dependency graph under Julia's scope rules. They do not run yet (go-embedded-julia's runtime is milestone M3): the cells that read one are blocked and say so. More → R cells (```r) are parsed with go-embedded-r's parser, identical to R 4.6.2 on R's own sources, and checked in the same way: syntax errors at their line in R's words, names in the graph, and a cell that cannot be analysed from its text (<<-, eval, library) depending on every cell above it. They run on go-embedded-r's evaluator in one shared environment (v0.10.0), and since v0.12.0 each cell is bounded: 512 MiB of vectors, 50 million steps, 30 s. The browser playground does not run them. More →" + blurb = "The kernel, the notebook command (run, html, watch, serve, irb) and the HTML export: format parses the Markdown, analysis builds the dependency graph from the syntax, gen writes the Go program, kernel compiles and drives it through runtime and keeps results and values, export writes the page. Ruby cells (```ruby) run on rbgo, a Ruby written in Go, with the go-scikit bindings (Stats, Special, Optimize, Integrate, DataFrame, Plot, NDArray), and share their variables with the Go cells. --timeout and --memory stop a runaway cell in either language. notebook irb is the same Ruby as an interactive session, as irb: => inspect after each input, _, multi-line input decided by rbgo's parser, Tab completion and history in a pure-Go line editor (go-ruby-reline), each input in a worker that --timeout, --memory or Ctrl-C can stop without losing the prompt, and --save to keep the session as a notebook. More → Julia cells (```julia) are parsed with go-embedded-julia's parser and checked: syntax errors at their line with julia's message, names in the dependency graph under Julia's scope rules. They do not run yet (go-embedded-julia's runtime is milestone M3): the cells that read one are blocked and say so. More → R cells (```r) are parsed with go-embedded-r's parser, identical to R 4.6.2 on R's own sources, and checked in the same way: syntax errors at their line in R's words, names in the graph, and a cell that cannot be analysed from its text (<<-, eval, library) depending on every cell above it. They run on go-embedded-r's evaluator in one shared environment (v0.10.0), and since v0.12.0 each cell is bounded: 512 MiB of vectors, 50 million steps, 30 s. The browser playground runs them too (playground v0.14.0), in its second core, with R variables kept apart from the other languages: 512 MiB, 20 million steps, 10 s per cell, and a crash restarts the core with a message on the cell. More →" [[params.repos]] name = "playground" kind = "wasm · page" href = "https://github.com/go-notebook/playground" - blurb = "A notebook in the browser, with no server. The page shows the prose as text and each code cell as a syntax-highlighting editor (a plain text box if the editor fails to load); Ctrl+Enter runs the whole notebook again in the tab. A Go interpreter (yaegi) compiled to WebAssembly runs the cells, while the libraries they import — go-statistics, go-numerics, go-ndarray, go-plot — run compiled: only the notebook's own code is interpreted. Each run posts the whole notebook to a Web Worker and gets every cell's results back, one call in and one string out, so a long run neither freezes the page nor costs a call per widget. Ruby cells run there too, in rbgo with the go-scikit bindings: the page fetches the Ruby core only when the notebook has a Ruby cell. Julia and R cells are parsed and checked there too, with their badge saying not runnable yet; their parsers come with the second core only. Nothing reaches the network or a file system, and every figure goes through an allowlist SVG sanitizer. Deployed as /playground/ here, with notebooks about the notebook itself, and on go-statistics and go-numerics." + blurb = "A notebook in the browser, with no server. The page shows the prose as text and each code cell as a syntax-highlighting editor in Go Mono at 13 px, with a minimap on its right (a click moves the caret) and line annotations, a gutter marker and an inline panel on Ctrl+Shift+M, saved in the Markdown as a gonb:notes comment (a plain text box if the editor fails to load); Ctrl+Enter runs the whole notebook again in the tab. A Go interpreter (yaegi) compiled to WebAssembly runs the cells, while the libraries they import — go-statistics, go-numerics, go-ndarray, go-plot — run compiled: only the notebook's own code is interpreted. Each run posts the whole notebook to a Web Worker and gets every cell's results back, one call in and one string out, so a long run neither freezes the page nor costs a call per widget. Ruby cells run there too, in rbgo with the go-scikit bindings: the page fetches the Ruby core only when the notebook has a Ruby cell. R cells run there too, on go-embedded-r, in the second core (about 4.5 MB larger), bounded to 512 MiB, 20 million steps and 10 s. Julia cells are parsed and checked there, with their badge saying not runnable yet. Nothing reaches the network or a file system, and every figure goes through an allowlist SVG sanitizer. Deployed as /playground/ here, with notebooks about the notebook itself, and on go-statistics and go-numerics." [[params.repos]] name = "docs" kind = "site" diff --git a/layouts/index.html b/layouts/index.html index 83dfec4..8a9371e 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -74,7 +74,7 @@

Speed, kept values and order — together.

💾

On disk, across runs

Results and values are kept in the work directory, so a new kernel, or the next notebook run, starts where the last one stopped.

📄

A page with no scripts

notebook html writes a standalone page: no scripts, no external resources, raw HTML in the prose left out. A page made from someone else's notebook runs nothing of theirs.

✅

100% test coverage

Gated in CI on Linux, macOS and Windows.

-
🌐

In your browser

The playground runs notebooks, Go and Ruby cells, in WebAssembly in the tab: no server, no install.

+
🌐

In your browser

The playground runs notebooks, Go, Ruby and R cells, in WebAssembly in the tab: no server, no install.

diff --git a/playground/go.mod b/playground/go.mod index 5c776cc..1536bd4 100644 --- a/playground/go.mod +++ b/playground/go.mod @@ -2,7 +2,7 @@ module github.com/go-notebook/go-notebook.github.io/playground go 1.27.3 -require github.com/go-notebook/playground v0.12.0 +require github.com/go-notebook/playground v0.14.0 require ( filippo.io/age v1.3.2 // indirect @@ -82,6 +82,7 @@ require ( github.com/go-embedded-c/c v0.2.1 // indirect github.com/go-embedded-julia/julia v0.5.0 // indirect github.com/go-embedded-r/r v0.13.1 // indirect + github.com/go-embedded-r/tre v0.1.3 // indirect github.com/go-embedded-ruby/ruby v0.8.5 // indirect github.com/go-encryptions/unixcrypt v0.1.0 // indirect github.com/go-facter/facter v0.0.0-20260830120958-454b72e642ab // indirect @@ -105,7 +106,7 @@ require ( github.com/go-mustache/mustache v0.1.0 // indirect github.com/go-ndarray/ndarray v0.28.0 // indirect github.com/go-nokogiri/nokogiri v0.1.0 // indirect - github.com/go-notebook/notebook v0.14.0 // indirect + github.com/go-notebook/notebook v0.15.0 // indirect github.com/go-numerics/integrate v0.2.0 // indirect github.com/go-numerics/optimize v0.3.1 // indirect github.com/go-numerics/special v0.2.0 // indirect @@ -313,7 +314,7 @@ require ( github.com/go-widgets/mvvm v0.15.0 // indirect github.com/go-widgets/painter v0.17.0 // indirect github.com/go-widgets/textinput v0.1.1 // indirect - github.com/go-widgets/toolkit v0.374.3 // indirect + github.com/go-widgets/toolkit v0.375.0 // indirect github.com/go-widgets/toolkit/rougelex v0.2.0 // indirect github.com/go-widgets/tui v0.61.0 // indirect github.com/go-widgets/vcs v0.1.0 // indirect diff --git a/playground/go.sum b/playground/go.sum index 341257d..2eb38fd 100644 --- a/playground/go.sum +++ b/playground/go.sum @@ -208,6 +208,8 @@ github.com/go-embedded-julia/julia v0.5.0 h1:yLdnc0M+qycG8lbkDyH58RYushqdMOp2xdr github.com/go-embedded-julia/julia v0.5.0/go.mod h1:f8anO/Ngw/UB/9Fj/k9qX/F8LRgh90Bp1VaJ2SQsGgw= github.com/go-embedded-r/r v0.13.1 h1:dZQNZ9YDug3S0gIZ9JbTOBp+NoomuQoVpMBDfmH0VsY= github.com/go-embedded-r/r v0.13.1/go.mod h1:+SbBiE9KSTuc1kWNF6009Ixrs2tM2uQCuKxByngTWL4= +github.com/go-embedded-r/tre v0.1.3 h1:MuHk9dLUO51F6kr7j8mnu01bUMVBmOpVlrmO16qObjo= +github.com/go-embedded-r/tre v0.1.3/go.mod h1:UN9RKw3VLEJpNmxPO+4JRTediME4pYay0iWFUMY2SUc= github.com/go-embedded-ruby/ruby v0.8.5 h1:JGKa6Cz4ihKNVfooeeytuPsT133byK7CkZr04Px9PYQ= github.com/go-embedded-ruby/ruby v0.8.5/go.mod h1:2wJ+VJXuGxD+Zl98T0L+/OQN1c5J/eLq452MS7aVZ2M= github.com/go-encryptions/unixcrypt v0.1.0 h1:XWk4h9uCDd+T2hovOzgO0B2vOdJvAwi9nbOBVb3o62c= @@ -261,10 +263,10 @@ github.com/go-ndarray/ndarray v0.28.0 h1:9RWfw01uRUH1YqsVUpNllm01XEohqdSfsk4Kw0x github.com/go-ndarray/ndarray v0.28.0/go.mod h1:bDbGWswQLmTMh6V3LwvKUbpfHzeG4sZDcvuGnA0GC+s= github.com/go-nokogiri/nokogiri v0.1.0 h1:3Q3BewGHK16Bt34ggJeyf9xeIMJyA3dmfbIxARPgR9U= github.com/go-nokogiri/nokogiri v0.1.0/go.mod h1:zjghooYIK8Xfg+fL4/OUhROslx51xGsM3JKtB2TI0tg= -github.com/go-notebook/notebook v0.14.0 h1:Tm9mZkZb4rk5aYBB6aDvCjYLMOYahCKpMkr3dEsdEpU= -github.com/go-notebook/notebook v0.14.0/go.mod h1:kVOmlBr0TQt3XZUcJcY1Z4hJnl1UPz+5grPT5fNAK3M= -github.com/go-notebook/playground v0.12.0 h1:IT2t8HvXl/Pw94ugGfFawQDdLJ6C84OekN1tIJnxrio= -github.com/go-notebook/playground v0.12.0/go.mod h1:RRDrkC/YgjNYPxu27FGeo7Iqkc2xwW7R5E7UBdL2Hv0= +github.com/go-notebook/notebook v0.15.0 h1:YINDiZnu53vd8IYeN+7VBvceSP81SYm8hnWbpP4xrGo= +github.com/go-notebook/notebook v0.15.0/go.mod h1:kVOmlBr0TQt3XZUcJcY1Z4hJnl1UPz+5grPT5fNAK3M= +github.com/go-notebook/playground v0.14.0 h1:UElBr11A4RExGRvAGXcCXFwiIJ8Z29oL1QXVUfzr3bc= +github.com/go-notebook/playground v0.14.0/go.mod h1:+eX/Jd/AX4uE85dSSRRT/5MFuwmKKB/vS08jyuzEquI= github.com/go-numerics/integrate v0.2.0 h1:IkJhDimTc7nQETCixEvbbHhtOF36GbANBKJI3mJB3Kw= github.com/go-numerics/integrate v0.2.0/go.mod h1:ABjpcWy8ZSOg8j6S+7YRsvMJ2LpVkH4E64/CGet2gCw= github.com/go-numerics/optimize v0.3.1 h1:eYkT9BpORKSwXnDtEJxXfZ19qJT0cI2RH6xEL3VLZSU= @@ -684,8 +686,8 @@ github.com/go-widgets/painter v0.17.0 h1:PB/Xr0flFR9qL2/RPhbJOeyU6PPzcGyf3Qx4RRn github.com/go-widgets/painter v0.17.0/go.mod h1:8kERcZUoWNyLIas1NsMWiYynvvyx+hcB2cNIh0Bx0yc= github.com/go-widgets/textinput v0.1.1 h1:3NZD5CJm5XYSWA3YzQ64tXC86gnEQ0UlNPL5qJeIUSs= github.com/go-widgets/textinput v0.1.1/go.mod h1:Y/k3PDtUEMQ/4psCVKdmUStNWa/EsVAMcCKG2lEtQ5c= -github.com/go-widgets/toolkit v0.374.3 h1:Az5pJJeAlFSyxdUGkkWsPsJ3+JqEXiSbdejJX1dpC5s= -github.com/go-widgets/toolkit v0.374.3/go.mod h1:zVKiLPMvy2igZZtU7IQ1rqoH31+kb1z2C6PptbCwaHI= +github.com/go-widgets/toolkit v0.375.0 h1:cSKh1OIhytXTnO5i4EBiCY4/IoYupdcRaXABvMzEu9w= +github.com/go-widgets/toolkit v0.375.0/go.mod h1:zVKiLPMvy2igZZtU7IQ1rqoH31+kb1z2C6PptbCwaHI= github.com/go-widgets/toolkit/rougelex v0.2.0 h1:7EZ0sqD5ldLoRJAFktrz1gQovrv8pu2Spi8o0XROmAM= github.com/go-widgets/toolkit/rougelex v0.2.0/go.mod h1:L5tohfJJv2JBPg9qXOy9wyyVCJfeg+FPCoMPXVM+qKg= github.com/go-widgets/tui v0.61.0 h1:DmT5TOpCrnXBnG6t1060BvsaHLyJXEM23DWH4SpuGt8= diff --git a/playground/notebooks/5-r.md b/playground/notebooks/5-r.md index 5507083..1b541ae 100644 --- a/playground/notebooks/5-r.md +++ b/playground/notebooks/5-r.md @@ -1,40 +1,49 @@ -# R cells, checked here but not run +# R cells, run in your browser -A cell written in an `r` fence is **parsed and checked** here with [go-embedded-r](https://go-embedded-r.github.io/)'s parser, and it is **not run in the browser**: the WebAssembly cores of this playground do not link go-embedded-r's evaluator. The `notebook` command does run R cells, since go-notebook v0.10.0, on go-embedded-r's own evaluator (no external `R`), in one shared environment and bounded since v0.12.0 (512 MiB of vectors, 50 million steps, 30 s per cell). The badge on the cell says what happens here: *R · not runnable yet*. +A cell written in an `r` fence **runs** here, with [go-embedded-r](https://go-embedded-r.github.io/)'s evaluator compiled to WebAssembly. There is no external `R` behind it, and no server. The badge on the cell says **R**, and the output is what R prints. -The parser gives the same trees as R 4.6.2 on all of R's own sources, so the notebook knows what each R cell assigns and what it reads, and which Go cells depend on it. Go draws the size; the R cell reads `n` and assigns `xs` and `total`. +R's variables persist from one R cell to the next. This cell defines a function and some data: -```go -n := 10 +```r +square <- function(v) v^2 +xs <- square(seq_len(10)) ``` -The R cell below is well formed, so it is not an error. It does not run here either: its output says why, and no number comes back. `square` is an R function, and R variables stay in R. +The next R cell reads them. Its last value is printed as R prints it, and `cat` and `message` write where R writes them: ```r -square <- function(v) v^2 -xs <- square(seq_len(n)) total <- sum(xs) +total +cat("mean of the squares:", mean(xs), "\n") +summary_of <- c(min = min(xs), max = max(xs), spread = max(xs) - min(xs)) +summary_of ``` -This Go cell reads `total`, which the R cell assigns. The name analysis sees that, so the cell is **blocked**: it waits for the R cell, and says so, instead of failing on a name that never arrives. +A warning comes the way R gives it, after the output of the cell: -```go -m := total + 1 +```r +ratio <- function(a, b) { + if (b == 0) warning("division by zero") + a / b +} +ratio(1, 0) ``` -A cell that does not read anything from R is not held back. It runs as usual, whatever the R cells above it do: +R's variables **stay R's**, as in go-notebook: they do not cross to the Go cells, and the Go cells' variables do not cross to R. This Go cell has its own `total`, and the R cell above is not touched by it: ```go -n * 2 +total := 42 +total ``` -A mistake in an R cell is caught at the right line, before anything runs, in R's own words, and the cells that do not read it still run. This notebook would stop being published if one of its cells had one, so here is one, quoted. With a cell that reads +An error is R's own, `Error in call : message`, and stops the run, as in every language. This notebook would stop being published if one of its cells failed, so here is one, quoted. With a cell that reads + +> sqrt("a") -> y <- 2 -> x <- y y +the page shows `Error in sqrt("a") : non-numeric argument to mathematical function`, and the cells after it say they were not run. Try it: add an R cell with `sqrt("a")` and run the notebook. -the page shows `line 2:8: syntax error: unexpected symbol`, at line 2, column 8, where R finds a second name with no operator between them. Try it: add an R cell with `x <- y y` and run the notebook. +## Limits -Some R cannot be analysed from its text alone: `x <<- 1`, `assign(name, v)` with a computed name, `eval(parse(...))`, `attach`, `library`. Such a cell is **dynamic**: the notebook makes it depend on every cell above it, and every later cell that reads a name depend on it. +A browser tab must not run out of memory or freeze, so an R cell is bounded: 512 MiB of vector storage, 20 million calls and loop iterations, and 10 seconds. A cell that goes past one is stopped with a message that says which, and the page stays usable: `while (TRUE) 0` ends on the step limit. The files a cell writes live in a private in-memory tree, and the environment is empty: no file or variable of your machine is visible to it. -To run R cells, use `notebook run` or `notebook serve` on your machine. Follow go-embedded-r at [go-embedded-r.github.io](https://go-embedded-r.github.io/). +What is not here yet: packages (`library`), graphics, and linear algebra (`solve`, `qr`). The output is text. Follow the progress at [go-embedded-r.github.io](https://go-embedded-r.github.io/).