You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like plotly and its integration with R's ggplot, but I find that I cannot use the keyboard to interact with plotly charts or the button bar at the top of the charts. This is a concern when making websites more accessible to people with disabilities. Could this be added?
@chriddyp In the US there is a law, referred to as section 508, that governs web compliance for the federal government (at least) and is used as a benchmark by others. Basically one part says that anything you can do with the mouse you should be able to do with just the keyboard (note - not a lawyer).
So I guess at least you would want to be able to activate/interact with all of the controls on the button bar and click the colors on the legends (where appropriate) by tabbing through them or something similar. It would also be good if you could use the keyboard move the cursor to hover over the various charts and see the information that is displayed (coordinates or values or whatever).
It is possible we could add these in the future, but I'm not sure whether we should beyond very basic interactions. Plotly.js' main focus is on plotting the data and exposing an interface to view it - in my opinion, specific key events should be managed by the consumers of plots (i.e. webpages they are embedded in).
Simple pan/zoom controls would be useful (z for zoom in, shift+z for zoom out, arrow keys to navigate) and not too too difficult to implement. Legends would be a bit more difficult to make keyboard-friendly because visual aids would need to be added (they are in SVG, not HTML), and any sort of cursor on the plot would be a fairly significant addition.
For now, if you are embedding plots in a webpage and need a11y, I'd suggest using the javascript API to bind whatever actions are required to keys - it's a difficult thing to generalize beyond zooming and scrolling, but those are both fairly easily implemented by changing axis ranges and calling Plotly.relayout.
vargraph=document.getElementById('graph');Plotly.plot(graph,[{x: [1,2,3],y: [2,3,4]}],{});// Basic example to zoom on zwindow.addEventListener('keyup',function(e){varkey=e.keyCode ? e.keyCode : e.which;// 'z' key is 90if(key===90){varoldRange=graph._fullLayout.xaxis.range;varoldMin=oldRange[0];varoldMax=oldRange[1];varscaling=e.shiftKey ? -0.1 : 0.1;varnewRange=[oldRange[0]+(oldMax-oldMin)*scaling,oldRange[1]-(oldMax-oldMin)*scaling];Plotly.relayout(graph,'xaxis.range',newRange);}});
Thanks for this suggestion. For what its worth, my hope it to use plotly to create graphics in R and then server them on the web using RStudio's shiny /shiny server . I would like to avoid adding the extra javascript, but it is good to know that it can be done.
Some pretty basic shortcuts would already help tremendously especially when you have to use a laptop trackpad. I previously used matplotlibs interactive window and immediatly tried to use the shortcuts in plotly, too. The matplotlib toolbar shortcuts are listed here:
Typical keyboard interaction for a custom component is to use the TAB key (and SHIFT+TAB) to navigate into and out of the component, and to use arrow keys (UP, DOWN, LEFT, RIGHT) to navigate within the component.
Please try using your keyboard in any of these Oracle JET charts/visualizations. Notice also that they also use aria-label where invisible labels are needed for screen reader users, and sometimes they use role="img" or role="separator" and other aria to help clarify what various things represent.
I would like to give my idea about using key arrow left, right for the slider to redraw frames. moving slider by frames is not easily control especially when you have a very long range, so keyboard would be more convinient when you want to go through frame by frame easily
My team is also interested in this, and I'd like to note, in response to this early comment,
It is possible we could add these in the future, but I'm not sure whether we should beyond very basic interactions. Plotly.js' main focus is on plotting the data and exposing an interface to view it - in my opinion, specific key events should be managed by the consumers of plots (i.e. webpages they are embedded in).
that keyboard accessibility controls are also important for non-visual disabilities such as fine motor control or limited range of hand/arm motion.
THanks @vglaidler - we don't have anyone to put on this right now, but we'd be happy to prioritize review of a community PR if someone can put one together.
I've got a working version of this locally: a config option that makes the plot focusable, arrow keys move the hover label between points and traces, and a live region reads each point for screen readers. Scatter, bar and pie for now, no new dependency. Before I open a PR, would you rather have this as a plain keyboardNavigation: true option or under a config.accessibility object like was floated in #6680? Off by default either way.
Sure. It's a new file, src/components/fx/keyboard_navigation.js, that runs in _doPlot right after initInteractions when the config flag is on. It makes the plot div focusable with an aria-label and adds a hidden aria-live region.
Left/right move through points in a trace, up/down switch traces at the nearest point, Home/End jump to the ends, Escape clears it. Hidden traces and hoverinfo 'skip' get skipped.
For scatter and bar it calls the existing Fx.hover with curveNumber/pointNumber, so you get the normal hover label and plotly_hover events. Pie uses mouseover on the slice instead. The live region reads out the same text as the hover label.
It's off by default and staticPlot turns it off. Happy to open a draft PR if that's easier to look at.
Activity
chriddyp commentedon May 24, 2016
thanks for reporting @johnpauls ! could you elaborate more on what you would expect the keyboard interactions to be?
johnpauls commentedon May 24, 2016
@chriddyp In the US there is a law, referred to as section 508, that governs web compliance for the federal government (at least) and is used as a benchmark by others. Basically one part says that anything you can do with the mouse you should be able to do with just the keyboard (note - not a lawyer).
So I guess at least you would want to be able to activate/interact with all of the controls on the button bar and click the colors on the legends (where appropriate) by tabbing through them or something similar. It would also be good if you could use the keyboard move the cursor to hover over the various charts and see the information that is displayed (coordinates or values or whatever).
Thanks
mdtusz commentedon May 24, 2016
It is possible we could add these in the future, but I'm not sure whether we should beyond very basic interactions. Plotly.js' main focus is on plotting the data and exposing an interface to view it - in my opinion, specific key events should be managed by the consumers of plots (i.e. webpages they are embedded in).
Simple pan/zoom controls would be useful (z for zoom in, shift+z for zoom out, arrow keys to navigate) and not too too difficult to implement. Legends would be a bit more difficult to make keyboard-friendly because visual aids would need to be added (they are in SVG, not HTML), and any sort of cursor on the plot would be a fairly significant addition.
For now, if you are embedding plots in a webpage and need a11y, I'd suggest using the javascript API to bind whatever actions are required to keys - it's a difficult thing to generalize beyond zooming and scrolling, but those are both fairly easily implemented by changing axis ranges and calling
Plotly.relayout.And a live jsbin
johnpauls commentedon May 27, 2016
Thanks for this suggestion. For what its worth, my hope it to use plotly to create graphics in R and then server them on the web using RStudio's shiny /shiny server . I would like to avoid adding the extra javascript, but it is good to know that it can be done.
legg681 commentedon Apr 20, 2017
I'd like this feature, too.
Some pretty basic shortcuts would already help tremendously especially when you have to use a laptop trackpad. I previously used matplotlibs interactive window and immediatly tried to use the shortcuts in plotly, too. The matplotlib toolbar shortcuts are listed here:
https://matplotlib.org/users/navigation_toolbar.html
carmacleod commentedon Sep 5, 2018
Typical keyboard interaction for a custom component is to use the TAB key (and SHIFT+TAB) to navigate into and out of the component, and to use arrow keys (UP, DOWN, LEFT, RIGHT) to navigate within the component.
Please try using your keyboard in any of these Oracle JET charts/visualizations. Notice also that they also use
aria-labelwhere invisible labels are needed for screen reader users, and sometimes they userole="img"orrole="separator"and other aria to help clarify what various things represent.etpinard commentedon Jun 27, 2019
From #3989
Is it possible to have shortcuts for interactions with the graph?
E.g. I would like to have
left,right,up,down+and-ctrl+leftandctrl+rightctrl+upandctrl+downu, horizontal unzoomalt+x, vertical unzoomalt+ypgctrl+c(partly taken from gnuplot).
mzechmeister commentedon Jun 27, 2019
Thanks for pointing me here.
How I can fed this javascript snippet outlined above by @mdtusz from python to the html document?
mzechmeister commentedon Jun 28, 2019
I created a some more key bindings, that be tested here https://jsfiddle.net/jrL34keb/1/.
I found no way pass the additional javascript to python via the
plotfunction.But there are functions https://github.com/plotly/plotly.py/blob/dc1111170d017911699d0f940850c45bd4f3e98e/plotly/offline/offline.py#L371
which have a
post_scriptargument.As a bad hack, I made a decorator to a function, which generates itself post_javascript code, in order to append the binding script.
When putting the following code at the top of the python script, it appends automatically key bindings in every
offline.plotcall.mizeljko commentedon Jan 14, 2020
Is there any update on being able to navigate through plotly chart using keyboard?
fzyzcjy commentedon Mar 30, 2020
I wonder whether there are any updates? Thanks!
GitHunter0 commentedon Jun 17, 2020
Just Zoom In, Zoom Out and Pan shortcuts alone should be great. Thank you.
5 remaining items
mzechmeister commentedon Apr 11, 2023
BTW, the javascript part of my snippet I posted above is now maintained as a standalone file:
https://github.com/mzechmeister/csvplotter/blob/main/zoom_pan.js
The project readme explains the available shortcuts.
LeoDiep commentedon May 24, 2024
I would like to give my idea about using key arrow left, right for the slider to redraw frames. moving slider by frames is not easily control especially when you have a very long range, so keyboard would be more convinient when you want to go through frame by frame easily
deven298 commentedon Jun 28, 2024
+1 for adding keyboard shortcuts for exploring the graph. This will be very helpful. Will keep an eye here!
vglaidler commentedon Sep 15, 2025
My team is also interested in this, and I'd like to note, in response to this early comment,
that keyboard accessibility controls are also important for non-visual disabilities such as fine motor control or limited range of hand/arm motion.
gvwilson commentedon Sep 23, 2025
THanks @vglaidler - we don't have anyone to put on this right now, but we'd be happy to prioritize review of a community PR if someone can put one together.
emilykl commentedon Aug 27, 2026
I believe that the modebar portion of this issue is addressed by #7429, which added the ability to navigate the modebar buttons via the keyboard.
scottcampbelldata commentedon Oct 9, 2026
I've got a working version of this locally: a config option that makes the plot focusable, arrow keys move the hover label between points and traces, and a live region reads each point for screen readers. Scatter, bar and pie for now, no new dependency. Before I open a PR, would you rather have this as a plain
keyboardNavigation: trueoption or under aconfig.accessibilityobject like was floated in #6680? Off by default either way.camdecoster commentedon Oct 9, 2026
Could you explain how your solution works?
scottcampbelldata commentedon Oct 9, 2026
Sure. It's a new file, src/components/fx/keyboard_navigation.js, that runs in _doPlot right after initInteractions when the config flag is on. It makes the plot div focusable with an aria-label and adds a hidden aria-live region.
Left/right move through points in a trace, up/down switch traces at the nearest point, Home/End jump to the ends, Escape clears it. Hidden traces and hoverinfo 'skip' get skipped.
For scatter and bar it calls the existing Fx.hover with curveNumber/pointNumber, so you get the normal hover label and plotly_hover events. Pie uses mouseover on the slice instead. The live region reads out the same text as the hover label.
It's off by default and staticPlot turns it off. Happy to open a draft PR if that's easier to look at.
camdecoster commentedon Oct 13, 2026
Please open a draft PR. It will be easier to talk through your solution that way.