Comments (10)
I opened #18 for the Python 3 issue in the last cell.
Also opened #19 to track allowing communication between outputframes. The technique with this API would be to send a message from one output to another output then invokeFunction from the output which is to be modified by the kernel.
from colabtools.
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.
from colabtools.
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.
from colabtools.
google.colab.kernel.invokeFunction
is now available, a notebook showing how to use it (and a bit more):
https://colab.research.google.com/notebook#fileId=1sYg2maTOT3GrCGS7R7WSxJcM3RsHjHAH
from colabtools.
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
from colabtools.
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 output.redirect_to_element
to change an element within the current cell. But I may want to call many python codes from different cells but want all the output to redirect to the first output cell. Maybe something like a dashboard where you try different python commands, but on the same output.
from colabtools.
@blois
Would it be possible to support invoking functions defined in JS from Python? I know that we can do eval_js
to get around, however, I think for real-time communication (as supported by comms message) there is a big overhead.
I think it would be great if the same API can be supported the other way around. What do you think?
from colabtools.
@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.
from colabtools.
from colabtools.
IPython iopub does support it but Colab does not at this time- #587.
from colabtools.
Related Issues (20)
- The webpage freezes when this command is run in vim HOT 6
- Save and Pin Revision HOT 1
- Change Runtime Type UI Issue HOT 2
- Try implementing the ‘exit’ statement HOT 2
- unable to use python cudf package HOT 2
- Auto zoom in HOT 2
- Float not Callable HOT 1
- I subscribed to PRO but cannot use T4 And the daily usage time is less than 4 hours HOT 4
- Code error cuase the colab cell to crash HOT 3
- Colab didn't keep my save history and because of that, I lost 5 hours of work HOT 1
- Code not using GPU despite it being enabled HOT 2
- Dropdowns no longer show defined options HOT 4
- List being mistaken for IntVar in OR-Tools, causing failure. HOT 1
- dictionary HOT 1
- Github does not render my commited notebook from Colab HOT 1
- Add a cell from another cell. HOT 5
- Red line doesn't plot on Machine Learning Crash Course Simple Linear Regression with Synthetic Data exercise HOT 3
- fooocus not working HOT 1
- I have a PRO subscription and it only has 12gb of RAM, why? HOT 3
- When I ran the "ControlNet" cell in the startup file "fast_stable_diffusion_AUTOMATIC1111", it never ended. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from colabtools.