Welcome to the forum, Vic — that’s a cool idea! Since viewof
has to be statically declared, and expects a DOM element with a value
property firing input
events, I can’t think of a way to use viewof
selectively or make it work with the standard Inspector.
Are you assigning x
to y
here because you want to use the Table’s checkboxes to filter the values? If you don’t care about the checkboxes (or referencing the value of their output), then this cell could just be Array.isArray(x) ? Table(x) : x
and you could refer to x
elsewhere, no need for y
.
The other (harder!) possibility is to make a custom version of the inspector that works like a view. I’ve sometimes wanted something like that myself; e.g., you can imagine a JSON inspector that lets you select a child as the value of the cell, for recursive drilldown stuff. And I’ve certainly wondered about more control over how the default inspector shows different kinds of things. Hm… looks like the heart of the inspector is here: inspector/inspect.js at master · observablehq/inspector · GitHub. Maybe we could just set the value
on that and it’d work with viewof?
But for now I think my pragmatic advice is that it’s an elegant idea which the current implementations make tricky, and I’d just use two separate cells there.