I agree with Grant that the preferred way of doing this would be to use the JupyterLab command system. You could write a mime renderer that takes JSON data and runs corresponding command. Then you don't have to send it JavaScript code over the wire.
On Fri, Nov 30, 2018 at 9:17 AM Grant Nestor <[email protected]> wrote: > Hi Florian, > > This certainly was one nice thing about classic notebook: the global > `jupyter` variable. > > If you run JupyterLab in dev-mode, you get a global `window.lab` variable > that gives you a handle on the application. This is a good starting point. > To add a new cell, you can call > `window.lab.commands.execute('notebook:insert-cell-below')`. You can call > that in the browser console or in a cell: > > ```py > %%js > window.lab.commands.execute('notebook:insert-cell-below') > ``` > > If you want to run a cell: > `window.lab.commands.execute('notebook:run-cell-and-select-next')` > > You can find these commands by searching the command palette and then > searching the jupyterlab source code for the command title. > > Another relevant project is jyve which gives you several custom Jupyter > JS-based kernels that expose JupyterLab internals outside of dev-mode: > https://github.com/deathbeds/jyve > > We are weary to expose this outside of dev-mode by default because of the > consequences that running arbitrary code could have on the user's lab > environment and system. We could consider adding a setting to the > javascript-extension allowing users to override this behavior so that it's > not default but possible. > > Feel free to open an issue on the jupyterlab repo. > > Grant > > On Friday, November 30, 2018 at 3:16:09 AM UTC-6, Florian Wetschoreck > wrote: >> >> Hi, >> >> there are good reasons why currently it is not allowed to execute >> arbitrary Javascript in JupyterLab. >> Also, there is a fix with the javascript extension package which exposes >> the window, document and element objects. >> https://github.com/jupyterlab/jupyterlab/pull/4515 >> >> However, we need access to more (internal) objects if we want to add >> cells or execute cells etc >> >> Therefore, I want to extend the current Javascript extension package to >> expose even more context for users who know what they are doing. >> The goal is to have another more powerful javascript extension which >> exposes all relevant objects to fully manipulate JupyterLab without having >> to go through the process of writing a custom extension. >> >> Do you have any advice on this endeavor? For example: *which objects to >> expose?* >> How to install the extension without interfering with the existing >> javascript MimeRenderer. Or maybe: how to overwrite the existing Javascript >> MimeRenderer. Is it possible to have both side by side? eg to import >> Javascript and/or JavascriptFullAccess from IPython.display >> >> Any help is highly appreciated. >> >> Florian >> >> -- > You received this message because you are subscribed to the Google Groups > "Project Jupyter" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jupyter/e456cda7-901a-4d3d-a764-9078ff9fd68a%40googlegroups.com > <https://groups.google.com/d/msgid/jupyter/e456cda7-901a-4d3d-a764-9078ff9fd68a%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Brian E. Granger Associate Professor of Physics and Data Science Cal Poly State University, San Luis Obispo @ellisonbg on Twitter and GitHub [email protected] and [email protected] -- You received this message because you are subscribed to the Google Groups "Project Jupyter" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/CAH4pYpSsL3cYR-4s_1kyZ1-s-59DzTnjXxoudXHUixCGhw0RpA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
