Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow specifying alt text for IPython.display.Image. #12864

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

Merged
merged 3 commits into from
Oct 6, 2021

Conversation

blois
Copy link

@blois blois commented Mar 19, 2021

For accessibility reasons users should be encouraged to add meaningful alt text to images. Currently there is no recommended way to do this using the standard Image object. Adding this field is a step towards having a common way for notebook renderers to support alt text and towards encouraging libraries creating images to add meaningful alt text.

See https://www.w3.org/standards/webdesign/accessibility#examples

Currently JLab just does https://github.com/jupyterlab/jupyterlab/blob/master/packages/rendermime/src/renderers.ts#L674.

I'd like to see the ecosystem get to the point where titles on graphs displayed as images automatically become alt text for those images.

For accessibility reasons users should be encouraged to add useful alt
text to images. Currently there is no recommended way to do this using
the standard Image object. Adding this field is a step towards getting
a common way for notebook renderers to support alt text and towards
encouraging libraries creating images to add meaningful alt text.
@bollwyvl
Copy link
Contributor

This is brilliant, and we should do it at the syntax level so that people can adopt it easily.

However, alt is a subset of a much larger ecosystem that spans a number of concerns, including internationalization, intent, etc. in addition to assistive technology awareness.

Ideally, we'd encourage consistency at the metadata level by adding "blessed" terms to the nbformat JSON schema so that clients aren't playing guessing games. The best of worlds would be to identify an existing standard, whether in JSON schema or whatever: my pick for this would be the web annotation data model which has mappings to w3c annotation-aria which can be accessibly embedded in html.

Practically, this would mean replacing:

"metadata": {"image/png": {"alt": "a picture of an elephant"}}

to...

"metadata": {"image/png": {
    "annotations": [
      # some more verbose JSON that other tools can read and reason about
    ]
  }
}

For some related things around making complex things describable, the p5 folk have done and written about some sterling work.

🛎️ @tonyfast @isabela-pf @manfromjupyter

@blois
Copy link
Author

blois commented Mar 19, 2021

I honestly do not have much experience in this area and am happy to defer to others for a more formal specification if there is interest in that direction.

I think this is particularly important because while many people have been doing great work to make the tools accessible for the authors of these notebooks this seems like an obvious gap for the readers of these notebooks, especially given the plethora of publishing avenues.

@bollwyvl
Copy link
Contributor

@blois really, thanks for starting this: I don't think anybody is experienced at this point, as we're trying to do something relatively difficult across a large number of pieces.

given the plethora of publishing avenues.

This is definitely the motivation for getting the metadata right. With the right metadata, we can enrich:

  • the library experience: as you've started, every kernel completion request can encourage adding this information
  • the authoring UI: Lab can have offer tools for annotating stuff, post-hoc, if you don't control the underlying code
  • "raw" generated HTML: nbconvert and nbviewer can show annotations
  • "soft" publication: sphinx, jupyter-book, etc. can present and make this information searchable
  • "hard" publication: more advanced PDF pipelines can make this work (not just browser screenshots)

Starting where you have is a really great place!

@blois
Copy link
Author

blois commented Mar 19, 2021

@bollwyvl If the desire is more than a plain string then it probably makes sense for this to be specified in nbformat first. I had started here since it appears to be the de facto specification for output metadata fields.

@blois
Copy link
Author

blois commented Apr 5, 2021

I'd prefer to avoid broadening the scope of this change to to encompass more accessibility features across more types of outputs as I feel that work is much larger, more speculative and lacks a clear owner. Adding an alt field to the metadata is a straightforward fix to the problem.

If there can be a more generalized set of accessibility metadata added to nbformat and outputs then it should be entirely reasonable for those to supersede simpler alt fields similar to how outputs themselves contain multiple prioritized formats.

Please let me know if there are further changes I should make here, otherwise feel free to close this PR if an nbformat specification approach is preferred.

@manfromjupyter
Copy link

I personally prefer keeping it as:

"metadata": {"image/png": {"alt": "a picture of an elephant"}}

The closer we can keep it to what that coding languages already exists (HTML, JQuery, etc) the better. Users shouldn't have to learn a new language or way of doing things just to support persons with disabilities/handicaps. alt is preferred and if that's already in the product, I say don't change it, but that's just me.

@Carreau
Copy link
Member

Carreau commented Apr 9, 2021

Sorry for the delay in reviewing / merging.

I have no opposition to this, it's just unclear to me if you want to get that in as is, or build consensus first.
I'm happy to get this in master, Ipython 8.0 will not be released soon, so there is still time if this gets in to be refined.

Let me know and I'm happy to merge.

@blois
Copy link
Author

blois commented Apr 9, 2021

If someone is interested in picking up the work to formally spec accessibility for outputs then I think this PR should be dropped. I opened jupyter/accessibility#37 and attended the regular meeting to discuss, I do not believe anyone currently has the time to pick up the larger work.

I don't think there's any immediate urgency for this issue and am fine waiting to see if we can build traction elsewhere.

The one thing is that once some variant of this lands is that it may be good to try to get matplotlib images to automatically fill in the alt text. I believe the primary work would be somewhere in

def select_figure_formats(shell, formats, **kwargs):
and it may be nice to try to get this into the same release. I'll start looking into this next step shortly.

@blois
Copy link
Author

blois commented Sep 26, 2021

At this point I believe that the approach proposed here is the best path forward. I'd like to see this merged so we can move on to encouraging users and libraries to include accessible alt text on images.

@minrk
Copy link
Member

minrk commented Sep 29, 2021

I agree that landing this as-is is the best start. It doesn't preclude more detailed abstract approaches, and we shouldn't have to wait for those. This is simple, straightforward, and solves a real issue without introducing any conflict with other ideas.

@isabela-pf
Copy link

I'm not speaking from a technical background here, but I would love to see this happen. I've had people in multiple communities now ask me for best practices on how to describe images like this, so I think it this would be a great step in getting a standard and supported method for alt text.

Since this has an approval, what are the next steps to getting this merged?

@blois
Copy link
Author

blois commented Oct 6, 2021

I believe that the next step is that someone with write access to the repo needs to merge it. Please let me know if there is any action required on my part.

@Carreau Carreau added this to the 7.29 milestone Oct 6, 2021
@Carreau
Copy link
Member

Carreau commented Oct 6, 2021

THanks, let's get that in an iterate if necessary.

@Carreau Carreau merged commit 59e313b into ipython:master Oct 6, 2021
@lumberbot-app
Copy link
Contributor

lumberbot-app bot commented Oct 6, 2021

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout 7.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 59e313b13998ab355470ce8b89c468e3399f07e8
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #12864: Allow specifying alt text for IPython.display.Image.'
  1. Push to a named branch :
git push YOURFORK 7.x:auto-backport-of-pr-12864-on-7.x
  1. Create a PR against branch 7.x, I would have named this PR:

"Backport PR #12864 on branch 7.x (Allow specifying alt text for IPython.display.Image.)"

And apply the correct labels and milestones.

Congratulation you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove Still Needs Manual Backport label once the PR gets merged.

If these instruction are inaccurate, feel free to suggest an improvement.

@lumberbot-app lumberbot-app bot added the Still Needs Manual Backport Added My MrMeeseeks when a backport fails. Help by backporting it, solving conflicts, send PR. label Oct 6, 2021
@Carreau Carreau removed the Still Needs Manual Backport Added My MrMeeseeks when a backport fails. Help by backporting it, solving conflicts, send PR. label Oct 29, 2021
@Carreau Carreau modified the milestones: 7.29, 8.0 Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants