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
Improved %%javascript
cell magic.
#13376
Comments
ping @Carreau |
I'm happy to deprecate the current javascript magic before 8.0, but I think that if anything a magic like that should be in a separate package to move at its own speed. Even in a separate package, we can make IPython depend on it, or auto load it when present. I also want to be really careful about "just swapping" as it may break a lot of existing code. |
Good points, I think it makes sense to be in a separate package, are you open to that package being in the IPython org? |
I should note that the entire code base for this is in a single notebook and the core code is 60 lines (Obviously the final version with tests/docs will be more). All that to say I don't have this in an existing repo that could be transferred over and would need a repo to exist that I could submit a PR to. |
Of course. The main question is wether it is the best place for people to find it. Will it work only with Lab ? Or also nteract/vscode/... ? Is the approach generic enough that pieces of it cold be reused by other kernels ? I'll trust you with the location, once you've decided I'm happy to add deprecation warnings to |
The implementation uses the HTML MIME type and should be reasonably portable across frontends that render the HTML output type. It should also be fairly straightforward to port to work with other kernels as the main logic is two string templates. In terms of location I propose we create an |
That sounds great ! |
BTW, the %%javascript is "just"
Should we also start deprecate the Javascript object ? |
Not sure yet, I need to see if it makes sense to use a corresponding class
in the new implementation. Will report back.
…On Wed, Dec 8, 2021 at 9:17 AM Matthias Bussonnier ***@***.***> wrote:
BTW, the %%javascript is "just"
@cell_magic
def javascript(self, line, cell):
"""Run the cell block of Javascript code"""
display(Javascript(cell))
Should we also start deprecate the Javascript object ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13376 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAGXUCC35BOQ4X4L2DXFPTUP6HJXANCNFSM5JSKIUXQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
Brian E. Granger
Senior Principal Technologist, AWS AI/ML ***@***.***)
On Leave - Professor of Physics and Data Science, Cal Poly
@ellisonbg on GitHub
|
In the scope of this I think it would also be good to think about how to expose an API from the host application to the Javascript module. The goal would be to enable these Javascript outputs to leverage Comms and possibly other APIs with a standardized API. There's a bit of discussion on this general idea in https://github.com/Quansight-Labs/jupyter-output-spec. For implementation and end user ease-of-use it should be as simple as the user optionally adding a I did a very primitive exploration of this in JupyterLab at https://github.com/blois/js-module-renderer/. |
Just to follow up on #13376 (comment) in Colab we have these capabilities exposed off of the window object to support rich visualizations without requiring extensions similar to classic notebook (full api). This works well but:
The goal here is to allow some degree of the customization that was available in Jupyter Notebook in JupyterLab and other clients, in a standardized manner. I also believe that an implementation must also preserve the simplicity of the module examples #13376 (comment) any top-level function should not be required but it would be used if present. |
I'm going to bump that past 8.0, I've marked the current JS magic as pending deprecation (ie not deprecated yet but it will likely be). I don't have particular use of the %%javascript, so I'll trust you all to make a decision and let me know. |
Maybe jumping to the details too soon, and better discussed in the upcoming repository, but I prefer logging my questions here for now:
|
I note some talk about React. How about support for Vue? |
Is there any update on this feature? I'm trying to utilize JS charting libraries inside JupyterLab (which implies exchanging data between python and JS cells), and so far the only working solution I found is https://github.com/jorgehpo/notebookJS. It works fine, but is rather convoluted, and I wonder if there's a more straightforward way available in 2022? Thank you. |
@ellisonbg Ever since I read this issue and you mentioned sucrase, I thought that it was an excellent idea to do transpilation in the browser. I've turned a subset of this idea this into an ipywidget library called ipyreact: https://github.com/widgetti/ipyreact/ Also, this issue motivated me to add a cell magic, so after %load_ext ipyreact %%react
import confetti from "canvas-confetti";
import * as React from "react";
export default function({value, on_value, debug}) {
return <button onClick={() => confetti() && on_value(value + 1)}>
{value || 0} times confetti
</button>
}; Due to (preconfigured) import maps, Material UI also works out of the box, so you should be able to copy paste the example from https://mui.com/material-ui/react-rating/ and it will just work. Hopefully, this is also an inspiration to pick up the full idea of an improved %%javascript cell magic. |
Hi! The proposed cell magic sounds great. I'm considering some JS integration with Jupyter and wonder if the dev notebook be shared/published? Cheers
|
I have been working on am improved
%%javascript
cell magic and I wanted to run the idea by others to gauge interest. The existing%%javascript
magic uses eval on a string of JavaScript code. While this works, it is relatively difficult to load external JavaScript packages and it is awkward to work with the DOM. I have developed a prototype with the following features:type=module
. This allows users to directly import modules from CDNs that support modules, such as Skypack.display
function that takes a React element, native DOM element or list of thereof and renders it into the output of that cell.The result of all this is that a user can write code that looks like the following:
And it will "just work". I would propose that this improved magic replaces the existing javascript magic. We might also want to have multiple variants that handle plain javascript, typescript, etc. At this point, I mostly want to get feedback on this directly to see if there is interest in this being in IPython. Here are a couple of example of this in action:
The text was updated successfully, but these errors were encountered: