[Question]: Send data back to notebook cell #5339
-
I have created a custom package under Requirement:
Questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 11 comments
-
Hi @anant-k-singh! Note: I've moved your issue to a discussion. It looks like you're trying to build a custom transform for a Jupyter display type. You can find docs on how to do this in the
The Python function should return a display_data object with a unique media type that can be mapped to a React component on the client. The documentation linked above has more info on this.
Can you clarify what you mean here. I can interpret your question in one of two ways:
Both are feasible but I can provide guidance depending on what you mean. To get started, I'd recommend reading the docs mentioned above. If you have any follow-up questions, please post them here and I'll address. |
Beta Was this translation helpful? Give feedback.
-
Thanks @captainsafia ! Now I have better understanding of transforms I want to embed a visual/graph in notebook's output cell using a custom transform (i.e. React component) Hypothetical usage would look something like this: In [1]: In [2]: In [3]: Note: Here EmbedVisual and ExtractData are python functions which basically request for lets say media types application/my-visual and application/my-data-format respectively To make this work, I can of course embed the visual again in ExtractData but instead of returning the embedded visual, I can call the API on visual and return the required data. My questions are:
|
Beta Was this translation helpful? Give feedback.
-
You could do this on the client pretty easily. However, based on the code that you showed above the Based on your example, it seems like the best approach would be to have your If you wanted all this to happen entirely in the client, you could achieve it with two transforms. An
Yes, a transform can render whatever you want it to on the page. Of course, it would have to be an HTML element since it is rendered on the page. Perhaps you're referring to the fact that all transforms are associated with display_data objects that have a serialized JSON string representation that is stored in the notebook? |
Beta Was this translation helpful? Give feedback.
-
Regarding the second question:
As you can see in the When
Is custom transform fit for this or do you have other recommendation? |
Beta Was this translation helpful? Give feedback.
-
Ah, I see! Yeah, what you're describing is a plain-text display object. You can achieve this by having your |
Beta Was this translation helpful? Give feedback.
-
I'm sorry, this has become a long thread Please correct me if I am wrong, the display object is used to render HTML (JSX element) in the output cell In my scenario:
My understanding is, that JSX element returned by custom transform's react component would be rendered in the output cell even if it is just a string. How do I return a string after executing some JS logic without rendering it in output cell? |
Beta Was this translation helpful? Give feedback.
-
In that case, you could render nothing (aka return null from the render method) from the React component.
This is a particular challenging part of the design because two runtimes have to communicate the state of a variable to each other, the JavaScript runtime running in the user's browser and the Python kernel running on the users computer (or perhaps in the cloud somewhere). If possible, I'd recommend investigating if there is some way to get around having to execute the JS logic to extract the variable on the client. It'll make the implementation a lot cleaner and more portable across different Jupyter front-ends. |
Beta Was this translation helpful? Give feedback.
-
I went through some of the nteract docs: Please correct me if I am wrong with my understandings:
|
Beta Was this translation helpful? Give feedback.
-
Generally, true. The notable exception is ipywidgets which does allow syncing data from a client to a kernel, but that's sort of its own thing. The other points are correct. |
Beta Was this translation helpful? Give feedback.
-
I am not able to render ipywidgets in my nteract notebook (though there are no errors) |
Beta Was this translation helpful? Give feedback.
-
It does! I posted a comment on the regression that is causing this. |
Beta Was this translation helpful? Give feedback.
Generally, true. The notable exception is ipywidgets which does allow syncing data from a client to a kernel, but that's sort of its own thing.
The other points are correct.