-
Notifications
You must be signed in to change notification settings - Fork 686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for comms messages #6
Comments
There are a couple of separate issues here- IPython.notebook.kernel.execute: for security concerns, Colab does not allow execution of aritrary python code from Javascript. Rather, Javascript will be able to invoke specific Python callbacks. The callback must be registered from Python using the google.colab.output.register_callback method: https://github.com/googlecolab/colabtools/blob/master/google/colab/output/_js.py#L45. This has not yet rolled out into production: import google.colab.output
def DoSomething(a, b, c=0):
return "a=%d b=%d c=%d" % (a, b, c)
google.colab.output.register_callback('DoSomething', DoSomething) Once the python callback is registered, Javascript from an output which has executed within the current session can call google.colab.kernel.invokeFunction: const result = await google.colab.kernel.invokeFunction('DoSomething', [1, 2], {c: 3}) Comms: currently as you noted Comms are not supported in Colab. One important distinction is that in Colab, each cell's output is in it's own iframe and all user-controlled code is executed in those iframes. We could broadcast these messages to each iframe, but in the case of something like Jupyter Widgets, it's not typically expecting multiple instances of the widget manager running on the page. I'd still like to see what level of trickery we could add to get some level of compatibility here, but I'm pretty sure it's going to involve a good deal more work than just plumbing through the comms messages. |
I’m satisfied with google.colab.kernel.invokeFunction I only need a way to interact with output cell and make change to python variables. This suffices for my need. Thanks. So, it will roll out to production sometime soon, right? At that time, please make a simple example, e.g. click a button to do something, or allow drawing on canvas and send the image to python. Really appriciate Colab. |
Yes, it should roll out shortly after the holidays. FWIW, the frontend code is already available and you can patch in the Python code via: from google.colab.output import _js as __js_239
import json
functions = {}
def register_callback(name, function):
functions[name] = function
def invoke_function(name, args_json, kwargs_json):
args = json.loads(args_json)
kwargs = json.loads(kwargs_json)
return functions[name](*args, **kwargs)
__js_239.register_callback = register_callback
__js_239._invoke_function = invoke_function |
|
The last example "Persisting Updates" does not work with Python 3. BTW, how do I change the output of other cells? The last example show how to use |
@blois I think it would be great if the same API can be supported the other way around. What do you think? |
@oeway |
hi, thanks for the quick response. Good to know that the waiting can be
disabled with ignore_results.
Can IPython iopub support binary data? I think there are still overheads on
the encoding data to string, parsing the js code, decoding the string etc.
imagine sending binary data, for example a high resolution image, we will
need base64 etc. Don’t you think it will be more straightforward if support
invokeFunction in Python?
…On Fri 18 Oct 2019 at 17:28, blois ***@***.***> wrote:
@oeway <https://github.com/oeway>
eval_js has a second argument- ignore_result that when set to true will
not block the Python code waiting for the result. Otherwise there should
not be significant overhead between eval_js and comms messages- they are
all JSON messages delivered over the same IPython iopub channel.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6?email_source=notifications&email_token=AADU3S5NLWJU25RW7HDIEL3QPHIYLA5CNFSM4EI2IKG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBU3BUY#issuecomment-543797459>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADU3SZZ5ZKKMMQHQH4DM4LQPHIYLANCNFSM4EI2IKGQ>
.
|
IPython iopub does support it but Colab does not at this time- #587. |
Some tasks need interactions between JS frontend and python backend.
Please add support for IPython.notebook.kernel.execute(python_code)
Also, some modules like ipyleaflet, bqplot, and other Jupyter Widgets don't work without them.
The text was updated successfully, but these errors were encountered: