Skip to content
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

[WIP] Split out embed manager #1394

Merged
merged 26 commits into from
May 31, 2017

Conversation

pbugnion
Copy link
Member

@pbugnion pbugnion commented May 29, 2017

This is a very tentative PR to split out the embed manager from the jupyter-js-widgets package into its own embed-jupyter-widgets package. This PR arose from both comments in the code and a discussion around PR #1380.

Prior to this PR, to embed the widgets you had to include https://unpkg.com/jupyter-js-widgets@~3.0.0-alpha.6/dist/embed.js in the HTML. This distributed both the embed widget manager and the JS for the default widgets present in Jupyter. After this PR, you will have to include https://unpkg.com/embed-js-widgets@*/dist/index.js. The default jupyter widgets lose their special status: they are now bundled as an AMD library like any other set of custom widgets. They are then fetched from unpkg (or locally) dynamically when they are requested in the embed state.

This changes several things, some of which I was very unsure of, so it would be good to get some feedback:

  • the URL for the embed bundle is now different. This will break existing code that doesn't explicitly set the version number. This is particularly insidious because the old url https://unpkg.com/jupyter-js-widgets@~3.0.0-alpha.6/dist/embed.js still works: it just now releases an AMD packaged library which cannot be used by itself.
  • presumably this will affect the release process.
  • the web4 example is currently somewhat broken: we can easily load the new embed-jupyter-widgets as a local dependency, but I think it makes sense to load the core widgets from unpkg -- since this is what users will do most of the time. This won't work until there is a new version of the library on unpkg though.
  • the generateEmbedScript in embed-helper seems to be unused. Should it be removed?

AFAICT, this is what's left to do:

  • Update documentation on embedding
  • Actually generate a new release of jupyter-js-widgets on unpkg and check that embedding still works.
  • Generate an alternative style sheet for embedding? In particular, we could make the disconnected symbol go away.
  • Update the code snippet that the user is supposed to copy and paste when they click on Embed Widgets in the menu so it points to the new package.
  • Add method to retrieve URL.

@maartenbreddels
Copy link
Member

It would be really helpful to have a say ipywidgets.embed.get_embed_url() for #1387 and an alternative to jupyter/jupyter-sphinx#13

@pbugnion
Copy link
Member Author

@maartenbreddels That makes sense. Do you see this just returning a hard-coded URL (maybe with the version dynamically included)?

@pbugnion
Copy link
Member Author

pbugnion commented May 30, 2017

To test this PR:

  1. Create an HTML document with some widget state in a new directory $TEST_DIR:
<html>
    <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="./embed-jupyter-widgets.js"></script>

        <script type="application/vnd.jupyter.widget-state+json">

         {
             "version_major": 2,
             "version_minor": 0,
             "state": {
                 "1ba8af4bbc874fe581360d8f6734079d": {
                     "model_name": "SliderStyleModel",
                     "model_module": "jupyter-js-widgets",
                     "model_module_version": "3.0.0",
                     "state": {
                         "description_width": ""
                     }
                 },
                 "635ea1d3185746ef88b2a9453cdbf7ad": {
                     "model_name": "LayoutModel",
                     "model_module": "jupyter-js-widgets",
                     "model_module_version": "3.0.0",
                     "state": {}
                 },
                 "7c1d41e9e96b4f94ae9219b31257cd2e": {
                     "model_name": "IntSliderModel",
                     "model_module": "jupyter-js-widgets",
                     "model_module_version": "3.0.0",
                     "state": {
                         "style": "IPY_MODEL_1ba8af4bbc874fe581360d8f6734079d",
                         "layout": "IPY_MODEL_635ea1d3185746ef88b2a9453cdbf7ad"
                     }
                 }
             }
         }

        </script>

        <!-- <style> -->
        <!-- .jupyter-widgets-disconnected::before { -->
        <!-- content: "" ; -->
        <!-- } -->
        <!-- </style> -->

    </head>

    <body>
        <h1>Output embedding example</h1>
        <div id="widget-embedded-here">
            <script type="application/vnd.jupyter.widget-view+json">
             {
                 "model_id": "7c1d41e9e96b4f94ae9219b31257cd2e",
                 "version_minor": "0",
                 "version_major": "2"
             }
            </script>
        </div>
    </body>
</html>
  1. Compile the core widgets bundle by running npm run build in jupyter-js-widgets. This generates an AMD library in dist/embed.js. Move embed.js to the directory $TEST_DIR and rename it jupyter-js-widgets so it matches the module_name that the widgets require.

  2. Compile the embed manager by running npm run build in embed-jupyter-widgets. This generates a top-level library in dist/index.js. Move this to $TEST_DIR and rename it embed-jupyter-widgets.js so it gets picked up by the script tags.

@jasongrout jasongrout added this to the 7.0 milestone May 30, 2017
@jasongrout
Copy link
Member

@pbugnion - are you saying this PR is ready to review (i.e., remove the WIP in the title)?

@pbugnion
Copy link
Member Author

Thanks! It's ready for review, but there's definitely still some work that needs doing (I've highlighted what's left to do in checkboxes in the PR description). I just don't feel confident addressing what's left to do without you (or someone else) validating the approach so far.

Copy link
Member

@jasongrout jasongrout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this general approach looks good. Since you have to import jupyter-js-widgets anyway for the manager base class, you might just include jupyter-js-widgets by default at this point.

"dependencies": {
"@phosphor/widgets": "^1.2.0",
"font-awesome": "^4.7.0",
"jupyter-js-widgets": "file:../jupyter-js-widgets"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like the other managers (widgetsnbextension, jupyterlab_widgets) rely on a published version of jupyter-js-widgets, we'll probably update this when we release to point to a release instead of a file path.

@jasongrout
Copy link
Member

@pbugnion - are you around sometime today to have a video chat, or maybe in-person chat?

@pbugnion
Copy link
Member Author

A video chat sounds good, time zone issues notwithstanding (I live in London). I suppose mornings or early afternoons in EST would work best.

@pbugnion
Copy link
Member Author

Those changes look great, thanks!

@pbugnion
Copy link
Member Author

How were you thinking of loading the embed-jupyter-widgets version? The easiest seems to be to just add a (fixed) dependency on embed-jupyter-widgets in widgetsnbextension once embed-juptyer-widgets has been released, and load the version from there?

@jasongrout
Copy link
Member

How were you thinking of loading the embed-jupyter-widgets version? The easiest seems to be to just add a (fixed) dependency on embed-jupyter-widgets in widgetsnbextension once embed-juptyer-widgets has been released, and load the version from there?

If you're talking about what version to specify in widgetsnbextension, yes, for now hardcoding the embed-jupyter-widgets version there.

@jasongrout
Copy link
Member

What do you think about calling it jupyter-widgets-htmlmanager?

@pbugnion
Copy link
Member Author

jupyter-widgets-htmlmanager sounds good!

@pbugnion
Copy link
Member Author

To avoid merge conflicts or duplicating work you might be doing, I might try and tackle the documentation for this, unless you think there's something more pressing?

@jasongrout
Copy link
Member

I'm about ready to merge this. Just contemplating the name of the package...

@jasongrout jasongrout merged commit 92ef3e8 into jupyter-widgets:master May 31, 2017
@jasongrout
Copy link
Member

Thanks again @pbugnion for taking this on!

@github-actions github-actions bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Feb 14, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants