display
display copied to clipboard
Dynamic script / plugins
A dynamic plugin system would make the server even more versatile.
Instead of having a fixed set of commands, the client could instruct the browser to execute any Javascript thus loading plotting libraries on demand. This way the client would be able to extend the command set and we'd be able to add functionality through lua+js packages without having to update the display server and its static assets.
i've been thinking about the same, as I try to integrate bokeh.js plotting that I implemented for ITorch. Does it sound reasonable to add an "eval" endpoint that executes arbitrary javascript?
I'm trying to decide on the approach. There's a few options here.
-
raw html, like in #14 pro: attached as child to the new Pane, so does not need any more context to add custom DOM con: cannot resize the Pane to fit (although
document.currentScript.parent.parent
might give you the pane element) con: requires wrapping script in<script>
tags pro: easy way to add external scripts<script src=.../>
con: to allow script sharing, need to write some boilerplate (if (typeof(window.bokeh) === 'undefined'
)) -
raw string
eval()
pro: no need to wrap scripts con: external scripts require extra boilerplate:var el = document.createElement('script'); el.src = 'http://external'; document.body.appendChild(el);
con: no Pane context, where to add DOM?
-
mixed API that would take care of the boilerplate:
{ "command": "eval", "external": [ "http://external/xxx" ], "script": "function(pane) {...}" }
pro: easy external scripts pro: allows external script sharing -- no need to load the same external source twice pro: explicit Pane context pro: no need to add
<script>
tags
Does it cover all the essential scenarios? Would this support bokeh.js integration?
script tags in raw html (point 1) do not get executed unless the script is in another file. I tried #14 in the hope of solving this but turns out i cant. eval is the only way one can execute javascript sent over the network (from my brief google searches), though you probably know better.
and yes, either of (1), (2) or (3) would solve the bokeh.js integration.