Reactive HTML Notebooks

california-og | 358 points

I strongly agree with the premise of the article - HTML could be a fabulous substrate for computational notebooks!

But I didn't love the choices for how to implement it here. Dynamic, reactive HTML can be a lot more declarative than this, and Observable is cool, but strays from standard JS.

I started to build a reactive HTML system called Heximal that eventually will have notebook support, but it's declarative, based on HTML templates and custom elements with a expression / reactivity system (based on the TC39 Signals proposal) on top.

https://github.com/elematic/heximal

It's a bit like a mashup of HTMX, Tangle, Curvenote, and Polymer. Or like HTML if were natively reactive.

I think it will lend it self to graphical editing and notebook user cases quite well.

spankalee | 4 days ago

Really cool! I particularly liked your Python and SQLite demos. I find it interesting that you started with a through-the-web (TTW) editing loop, calling it a quine. While valid, the key weakness is persistance: TidlyWiki does basically the same thing, but saving your work is a headache because basically you need another headless server process to persist anything.

Personally, when wanting to do something similar[0], started with persistance, and of course this means files. Plain text files I can edit with my programmer's editor store and distribute using the file-system. This avoids the problem of having to recapitulate a programmers editor in the browser, which is non-trivial. In turn you have the problem of writing a fast server, but that is a rather fun problem to solve [1]. You side-stepped the problem by using basic content-editable sections, but it is a huge problem, second only to persistence.

One thing I see you face which I also faced is the fact you cannot export things from inside embedded scripts! This would be a nice feature to avoid mangling the global window object. (It would also, in my use case, make code generation easier.)

0 - Literate Markdown: https://simpatico.io/lit.md

1 - Reflector, what I call the small node server that transforms, zips and caches your markdown, with a filewatcher invalidator: https://simpatico.io/reflector

simpaticoder | 4 days ago

With all due respect to the considerable thought and effort you put into this, the ergonomics of this approach are hideous. Why would I ever care about the styling elements when I'm just trying to do some exploratory data analysis. This is exactly why things like Jupyter notebooks excel. Regardless kudos to your curiosity and implementing alternate ideas.

doug_durham | 4 days ago

The original author of Lit recently left Google and is working on something very similar to this AFAIK.

https://github.com/elematic/heximal

mdhb | 4 days ago

I enjoy the format of this post. Work from ground up to something interesting. Not tons of dependencies and framework here framework there blablabla hype.

To follow along it seems you can just copy paste the given snippets and understand step by step how it works. If I wrote something like this, I guess I would use literate programming in org-mode and export to HTML, to make it a blog post.

I still question fonts with built-in syntax highlighting.

zelphirkalt | 4 days ago

Reactive HTML but it’s almost entirely JavaScript, or am I misunderstanding something?

squeegee_scream | 4 days ago

I will soon make attempts to support this kind of HTML notebook in/for Raku. Right now Raku's "notebook solutions" are Jupyter-based or Mathematica-based.

antononcube | 4 days ago

I tend to agree with the premise of this article -- that [HTML is underutilized as a medium for disseminating scientific writing].

Some recent work related to this done by Will Crichton:

https://willcrichton.net/nota/ https://willcrichton.net/notes/portable-epubs/

agnishom | 3 days ago

Notebooks are hot these days! We also shipped our own version of a TypeScript notebook[1] but it takes quite different sides of the tradeoff: we want to run backend node code, so unlike this or observable we're not looking to run in the browser environment. Still, for many applications, this idea is a better take!

Kudos to the author.

https://github.com/srcbookdev/srcbook

nichochar | 3 days ago

I don't get the argument for using web technologies to complicate this process. What does this added complexity solve? If anything, it slows the process and remove much needed features like auto-completions, snippets, and extensions. Also, it makes collaboration harder, since, most likely, others aren't familiar with your setup.

You only need to setup one environment once and use it forever with minor incremental improvements as tech evolves.

If you are a n/vim user, you can accomplish this by:

1- Data exploration: text -> jupyter notebook via https://github.com/untitled-ai/jupyter_ascending that uses jupytext. This way, you can efficiently edit and run code from your text editor.

2- Writing: you can use https://github.com/lervag/vimtex for LaTeX

On top of these, you can use tmux with tmuxp to open projects instantly.

You can have a seamless process with Emacs using org mode [1] [2] and/or Auctex.

[1] https://sqrtminusone.xyz/posts/2021-05-01-org-python/

[2] https://martibosch.github.io/jupyter-emacs-universe/

yasser_kaddoura | 4 days ago

First of all, incredible. This is right up my alley.

I tried editing the pyodide one (which rendered fine before editing) on my phone (iphone 13 + brave) and it crashed and reloaded the page.

jasonjmcghee | 4 days ago

Author here! Happy to take questions!

mbo | 4 days ago

This reminds me of https://tiddlywiki.com/

n0rdberg | 4 days ago

Ohh that Windows XP dinosaur cursor brought back so many memories!

louismerlin | 4 days ago

This is awesome - I have been toying with building something like this so that i can host (raku) code examples and do literate programming. FWIW there IS a good raku plugin for Jupyter Chatbooks (https://raku.land/zef:antononcube/Jupyter::Chatbook), but it just seems kinda wrong for raku to need python to do this.

Can this example be widened to use server side code (I am not too bothered about syntax highlighting as maybe can make a font for that) - but it would be great to have some kind of message layer (like zmq in Jupyter) to connect to a remote language kernel perhaps using web sockets???

Raku does not (yet) target wasm so that option is out.

librasteve | 4 days ago

The cursor drives me nuts.

britzsquad | 4 days ago

Awesome implementation!

> 3. Export to .pdf for distribution

I was certain you were using something like https://pagedjs.org or https://printcss.net for the PDF export, but its just the SydJS or am I missing something?

Ringz | 4 days ago
[deleted]
| 4 days ago

Wow, this is lovely! I'm rather inspired to make something with it

jedimastert | 4 days ago

This breaks so bad for me on my phone :-(

gyre007 | 3 days ago

obervables move to modules makes a lot of this tenable. Im still using their hosted gui but this is inspiring me :)

cdaringe | 4 days ago

You made my weed.

revskill | 4 days ago