# library(highcharter)
<- data.frame(
data fruit = c("apple", "banana", "orange", "pear"),
count = c(2, 3, 5, 4)
)
highchart() |>
hc_add_dependency(name = "modules/accessibility.js") |>
hc_add_dependency(name = "modules/exporting.js") |>
hc_add_dependency(name = "modules/export-data.js") |>
hc_title(text = "Fruits") |>
hc_xAxis(categories = data$fruit) |>
hc_add_series(
data = data$count,
type = "column",
name = "Count"
|>
) hc_exporting(
enabled = TRUE,
accessibility = list(
enabled = TRUE
)|>
) hc_plotOptions(
accessibility = list(
enabled = TRUE,
keyboardNavigation = list(enabled = TRUE)
) )
Over the past few weeks I’ve been experimenting with the accessibility module from Highcharts using the {highcharter} package by Joshua Kunst. Highcharts is an SVG-based library for making interactive charts for the web. {highcharter} is an R package that wraps the Highcharts JavaScript library and its modules (Kunst 2021).
One of the things I like about {highcharter} is how it really mirrors the native API (which you can learn more about in its vignette on the topic, JavaScript API basics). Because they’re so closely tied together, all of the Highcharts documentation, in effect, becomes {highcharter} documentation. So, my “experiments” have largely consisted of converting examples from the former into the latter.
In this post, we’ll give a broad overview of the accessibility module, motivating examples, and make a basic, working example with keyboard navigation enabled.
Highcharts ∩ accessibility
Highcharts has fairly extensive accessibility features, and has engaged in some interesting collaborations and research on making data visualizations accessible, especially for those with visual impairments (Bert and Hayes 2018).
The Highcharts accessibility module enables a number of features—most notably usability through keyboard navigation and screen reader technologies. Though not part of the accessibility module, their accessible demo charts also make use of patterns and dash styles to improve contrast for those with colour blindness.
R accessibility resources and motivating examples
Silvia Canelón recently posted Resources for Data Viz Accessibility:
A selection of general and R-specific resources on how and why to make accessible data visualizations (Canelón 2021).
I noticed that, at the time (it had been last updated on 2021-10-14), it suggested that the accessibility module didn’t work with {highcharter}, and linked to a couple of GitHub issues in its repo (specifically #707, and #719) where unsuccessful in getting accessibility features to work through {highcharter}.
Having worked with {highcharter} a bit in the past, and knowing that “if you can do it in Highcharts, you can do it with {highcharter}” usually holds true, I thought I’d give it a whirl.
Guiding principles
There are a couple of principles I try to follow when figuring out coding “problems”—both of which are probably just ersatz versions of Jenny Bryan’s reprex do’s and don’ts.
Isolate your variables. Like many of the interactive (usually JavaScript-based) charting packages in R, {highcharter} works with {shiny}1. However, you can also use {highcharter} without shiny (e.g. in an R Markdown document like this one) and still get a lovely, interactive visualization in the form of an htmlwidget. Since my goal was to see if I could get the accessibility module to work with {highcharter}, I didn’t want to introduce shiny into the equation as an “extraneous” variable.
Follow a working example. Between the {highcharter} site and the Highcharts demos (all of which have options to edit in CodePen and JSFiddle), there is no shortage of working examples available with code! Though I know very little about JavaScript, the aforementioned resemblance between the Highcharts JS API and {highcharter} syntax make reading the “foreign” source code incredibly helpful 2.
Getting started…
As I came to discover, the first example in Highcharts’ Getting started with accessibility documentation (an accessible line chart) is actually somewhat complex from an R user’s standpoint. However, my plan was to mimic the examples from the Highcharts docs. So, it’s where I began.
Over in the land of {highcharter} documentation, I gave the Modules & plugins vignette a careful reading, since I’d be making use of at least one module (plus a few more, as I came to discover).
Because this missive has already gotten a bit long, I’m going to save the full line-chart example for a later post. However, something mentioned at the beginning of the Getting started docs turned out to be crucial to solving the mystery of Issue #707—the inclusion of the exporting and the export-data modules.
Fin
We’ve just scratched the surface of what can be done with the Highcharts accessibility module. Next time we’ll take a step-by-step look at recreating Highcharts’ accessible line chart demo.
References
Footnotes
See the highcharter Shiny examples vignette for details.↩︎
I also copied these examples to my machine as stand-alone applications to ensure I could make them work outside of the online editors↩︎
In fact, I wouldn’t necessarily call the following example “accessible” per se, since it doesn’t make use of some of the features to subsequently in this series.↩︎
Reuse
Citation
@online{averick2021,
author = {Averick, Mara},
title = {Adventures with the {Highcharts} Accessibility Module: {Part}
1},
date = {2021-11-10},
url = {https://quartoand.me/blog/2021-11_adventures-with-the-highcharts-accessibility-module-part-1},
langid = {en}
}