Method to access query string in Voila notebook

In case it helps anyone, I wasn’t having much luck using that notebook that ConorMc posted above, and so I reworked it to step through much what I think it was trying to demonstrate in a manner that works via MyBinder.org launches. Major caveat: works as a notebook; the javascript cell to get the full URL won’t work in Voila (see below).

passing full URL to Python via query string demonstrated via mybinder.org



The reason the approach used in the notebook fails in Voila is two-fold. The way the javascript is run with the %%javascript cell magic in the notebook I posted is not compatible with Voila. However, just because that route to run javascript doesn’t work in Voila, it doesn’t mean you cannot run javascript in code for Voila. Using Javascript imported from IPython.display you can use javascript in Voila if you use the right syntax to place the javascript code in the display(Javascript()). For example, the following will work in Voila to trigger javascript to display an alert window in Voila:

#based on https://github.com/voila-dashboards/voila/issues/743
from IPython.display import Javascript
display(Javascript('''alert("test")'''))

See other examples here and here.

However, even though other javascript works, I’ve been unable to get the command IPython.notebook.kernel.execute() to work in Voila. That is used in the notebook example to pass via javascript the string collected from the URL location into the notebook kernel. I don’t see how to pass that to Voila from javascript though. I don’t think getting IPython.notebook.kernel.execute() working is just a matter of not nesting it correctly in the right combination of quotes; however, there’s a slim chance I haven’t quite worked this out.