Skip to content

Adding Binder links to the Matplotlib gallery #11415

Closed as not planned
Closed as not planned

Description

@choldgraf

Hey all - we recently added a nifty new feature to sphinx-gallery that automatically generates Binder links for each sphinx gallery example. See the sphinx gallery docs as an example:

https://sphinx-gallery.readthedocs.io/en/latest/auto_examples/sin_func/plot_sin.html#sphx-glr-auto-examples-sin-func-plot-sin-py

I think it'd be cool if we had this for Matplotlib (e.g. each example would have a "launch binder" button at the bottom that could open an interactive version of the example for users).

However, there are a few caveats here:

  1. Matplotlib docs get a ton of users, and this might have unexpected results on mybinder.org if a gigantic influx of people happens. At the least, we'd likely hit the per-repo limit of 100 concurrent Binder sessions.
  2. Binder is still in beta (e.g. it won't have 100% uptime, though is pretty close to this, and may occasionally drop off if we have an outage)

That said, it'd be pretty cool if each of our users was one click away from interacting w/ the matplotlib examples on each page.

What do folks think about this? If we're +1 giving it a shot, I can put together a PR activating the Binder links on the matplotlib docs.

Activity

  1. ImportanceOfBeingErnest commented on Jun 11, 2018

    @ImportanceOfBeingErnest
    Member

    What happens if the limit is reached? Who maintains mybinder.org; would the use of this feature be within their envisionned use cases?

    From the matplotlib side one could make this an experimental feature, like

    image

    and see what happens?

  2. choldgraf commented on Jun 11, 2018

    @choldgraf
    ContributorAuthor

    When the limit is reached binder will display a message saying that the limit is reached for the repository. There's a chance that a gigantic influx of traffic would overwhelm the binder servers and the site would go down, though I think this is small. In that case, we'd remove the binder links from the matplotlib docs.

    Re: Binder's envisioned use case, I can confirm that interactive documentation is one of the envisioned use-cases, yes :-)

    When is the next release planned? One thing we could do is implement this PR at the beginning of a cycle, and then it's only exist in the /latest URL as a test run

  3. ImportanceOfBeingErnest commented on Jun 11, 2018

    @ImportanceOfBeingErnest
    Member

    In general there is of course a problem with those notebooks generated via sphinx-gallery: There is no control over whether a notebook is to be created/linked to by a certain example. This is important because many examples do not run in %matplotlib inline mode.

    So ideally one would have a directive flagg to set whether an example should (not) contain a notebook and even better, whether that example should use %matplotlib notebook instead of inline.
    This then quickly leads to even more general problems with sphinx-gallery which has no way to hide code/comments/directives from the output.

    In that sense one might also question in how far one should provide non-runnable notebooks to users.

  4. jklymak commented on Jun 11, 2018

    @jklymak
    Member

    Binder doesn't appear to work with %matplotlib notebook. What examples don't work in inline? We should proabbly start noting that in the example somewhere. A flag would be cool, if there is an easy way to impliment. Not sure what metadata we can enter into the examples as they are...

  5. ImportanceOfBeingErnest commented on Jun 11, 2018

    @ImportanceOfBeingErnest
    Member

    What examples don't work in inline?

    Well obviously all examples from the sections "Animation", "Widgets" and "Embedding" and I suppose others as well which use .draggable() or similar stuff.

    Not sure what metadata we can enter into the examples as they are.

    Currently none. Everything written in those files appears in the output, like e.g. # sphinx_gallery_thumbnail_number = 18 in the constrained_layout guide.


    What's important really is the question: What would weight more,

    • user excitement, being able to run most of the examples (not all as stated above) sometimes (if traffic is low enough) online;
    • or user frustration, not being able to run a certain example at a certain point in time.

    I'm personally undecided here, but those points may help people come to a conclusion.

  6. choldgraf commented on Jun 11, 2018

    @choldgraf
    ContributorAuthor

    Some quick thoughts:

    1. Binder should work fine with %matplotlib notebook. Which example didn't work for you @jklymak ?
    2. We could try and merge something into sphinx-gallery that calls "%matplotlib notebook" instead of "inline" with a flag, though this may be unnecessary complexity
    3. My 2 cents is that some interactivity is better than no interactivity
  7. jklymak commented on Jun 11, 2018

    @jklymak
    Member

    JavaScript output is disabled in JupyterLab

  8. choldgraf commented on Jun 11, 2018

    @choldgraf
    ContributorAuthor

    ah - I think that just means that an extension hasn't been enabled for JupyterLab on that Binder build. It works with the Noteboook UI

  9. jklymak commented on Jun 11, 2018

    @jklymak
    Member

    I just followed the links. No sure what the Notebook UI is.

    FWIW, I'm not 100% against this, but I think most users would be better served by downloading the code and running locally versus running in a remote instance. At some point they are going to want to run matplotlib locally, unless we are trying to send people to binder as a one-stop shop for data analysis. I'm not seeing the benefit of making this run remotely.

  10. timhoffm commented on Jun 11, 2018

    @timhoffm
    Member

    While generally it would be nice to be able to tinker with the examples online, I'm sceptical that we should hook to binder in it's current state.

    A feature that's not yet reliably working is creating frustration for the user. That would have to be sorted out before.

    • Wait till binder is out of beta for stability of service.
    • Do we have example download statistics? That would be a hint on the expected traffic on binder (though the interactive examples would probably be used more often by some factor).
    • Check with the mybinder operators if the traffic is ok.
    • 100 sessions seems quite little, given that probably many people will keep the example open in their browser even when not working on it directly. Is there a timeout?. If the session limit is reached most of the time, the feature is basically unusable.
    • Apart from the technical limitations, we'd also have to make sure that the examples really work. Probably start with a white-list. (That would also help controlling the initial amount of traffic.)
  11. ImportanceOfBeingErnest commented on Jun 11, 2018

    @ImportanceOfBeingErnest
    Member

    I do see the point of letting people run examples on the fly. This has something to do with being inviting and inclusive. People visiting matplotlib.org can directly try out how great this works by running some example and changing the color to "red" - "Oh wow, this is easy, I need that for my project."

    ... and that is exactly the problem when it comes to this feature only working sometimes or not at all when choosing a non-compatible example. Then it's more "Oh, this doesn't work, I can't even change the color to "red"; let's take some other library instead."

    Maybe a whitelist like @timhoffm just mentions is a good start; One could advertise a couple of examples to try out on the main page and make sure those are running fine.

  12. choldgraf commented on Jun 11, 2018

    @choldgraf
    ContributorAuthor

    a few thoughts:

    • Right now within sphinx gallery I don't think it's possible to include a white list for Binder links, but this might be something worth adding.
    • My intuition is that the vast majority of people will never run examples locally on their computer (e.g. most people just pip install matplotlib and never know where the examples are located on their machine). I think a lot more people would click on interactive links on the web.
    • It'll probably be a loooong time before Binder is ever "officially" out of Beta (we're doing sort of a gmail-style "beta forever" model for Binder)
    • re: user session destroying, yep we delete user sessions after periods of inactivity (fairly aggressively, the goal of Binder is to have short interactive sessions in general)
    • re: examples really working, anything that's not tagged sgskip should work fine in the Binder environment, provided that the repo is set up with the same environment that sphinx-gallery+CircleCI uses when it runs the examples

    (full disclosure here - I'm on the sphinx gallery team as well as the Binder team, so we could probably make some additions to one or another project if it'd be valuable here)

  13. jklymak commented on Jun 11, 2018

    @jklymak
    Member

    My intuition is that the vast majority of people will never run examples locally on their computer (e.g. most people just pip install matplotlib and never know where the examples are located on their machine). I think a lot more people would click on interactive links on the web.

    Users must run some code locally, at some point in their careers. Presumably some of it is cut and paste from the examples, and/or downloaded from the examples pages. I'm not seeing how going to binder to run the example is better than doing it locally if I want to play with the examples, unless I don't already have a python/matplotlib environment installed. But even if I didn't, I'm not getting the long-term use case for a newbie to start using binder. Why should we, as a package, be guiding people there?

  14. tacaswell commented on Jun 11, 2018

    @tacaswell
    Member

    I am 👍 on this in principle. Reducing the friction of 'let me play with this' to clicking a link is definitely a good thing!

    Is ipympl installed in the binder images? If so %matplotlib widget should work and give you interactive figures under jupyter lab.

    We do run all of the examples as part of building the docs so we know that they are at least valid python and produce reasonable output. The best way to get feedback on which versions of the notebooks work is to open them up and get user feedback on what is broken!

  15. added this to the v3.0 milestone on Jun 11, 2018
  16. 16 remaining items

  17. modified the milestones: v3.4.0, v3.5.0 on Jan 27, 2021
  18. modified the milestones: v3.5.0, v3.6.0 on Sep 25, 2021
  19. modified the milestones: v3.6.0, v3.7.0 on Jul 8, 2022
  20. tacaswell commented on Feb 9, 2023

    @tacaswell
    Member

    This is also related to #22634

  21. github-actions commented on Jul 19, 2024

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  22. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Aug 19, 2024
  23. agriyakhetarpal commented on Jan 13, 2025

    @agriyakhetarpal

    Hi all – apologies for commenting on an issue that's been around for almost seven years, but I've posted an update on #22634 that was linked above. That PR aims to add an interactive REPL for Matplotlib's docs homepage running via Pyodide/JupyterLite and WebAssembly, and this issue deserves to receive the surrounding context as well: the combination of Sphinx-Gallery through its JupyterLite integration, and its underlying Sphinx extension (jupyterlite-sphinx) are pretty stable at this point and should overall allow replacing Binder with notebooks that can run Matplotlib with in-browser computation, avoiding server costs.

    To address #11415 (comment), it is possible to download the notebooks with Sphinx-Gallery. Also, it is theoretically possible to disable a few examples for JupyterLite through Sphinx-Gallery's integrations based on an sgskip label (though, maybe disabling only under JupyterLite and not elsewhere needs to be a feature request or something?).

    After all, one can expect that it would be useful for both docstring-based API examples that showcase functionality and for the galleries, even if it's on an experimental basis and users are warned that certain notebooks might not work. It is to be noted that scikit-learn has had this integration already for their docs' notebooks and they have been maintaining it so far, to the point of Pyodide/WASM as an officially supported platform: scikit-learn/scikit-learn#23727

    All in all, if this item is still in the ambit, I would be happy to put together a PR. :)

    Here are some links to contemporary interactive documentation efforts in the ecosystem for Scientific Python projects:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Documentationstatus: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions