rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
1.97k stars 199 forks source link

[accessibility] Row names (i.e., stub) have to use <th> tag #678

Closed jooyoungseo closed 2 years ago

jooyoungseo commented 3 years ago

Currently, stub (AKA, row names) are denoted with <td> tag for html output.

However, this is not a recommended practice for accessibility purpose.

As of writing this issue, the row names are not auto-announced when navigating row by row with screen readers.

Please consider using <th> instead. That will resolve this issue.

Plus, ideally, it would be best if we could add scope = "row" attribute as well.

Please consult with this technical spec.

Reprex

# Load required packages
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(gt)

# Create a tibble
islands_tbl <-
  dplyr::tibble(
    name = names(islands),
    size = islands
  ) %>%
  dplyr::arrange(desc(size)) %>%
  dplyr::slice(1:10)

# Make a gt table with row names (i.e., stub)
islands_tbl %>%
  gt::gt(rowname_col = "name")
size
Asia 16988
Africa 11506
North America 9390
South America 6795
Antarctica 5500
Europe 3745
Australia 2968
Greenland 840
New Guinea 306
Borneo 280

Created on 2020-11-07 by the reprex package (v0.3.0.9001)

Session info sessioninfo::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 4.0.3 (2020-10-10) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz America/New_York #> date 2020-11-07 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.3) #> backports 1.1.10 2020-09-15 [1] CRAN (R 4.0.3) #> checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.3) #> cli 2.1.0 2020-10-12 [1] CRAN (R 4.0.3) #> colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.3) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.3) #> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3) #> dplyr * 1.0.2 2020-08-18 [1] CRAN (R 4.0.3) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.3) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.3) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.3) #> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.3) #> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.3) #> ggplot2 3.3.2 2020-06-19 [1] CRAN (R 4.0.3) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.3) #> gt * 0.2.2 2020-11-07 [1] Github (rstudio/gt@6287519) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.3) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.3) #> htmltools 0.5.0.9002 2020-11-01 [1] Github (rstudio/htmltools@0741213) #> knitr 1.30.2 2020-10-25 [1] local #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.3) #> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.3) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.3) #> pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.3) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.3) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.3) #> R.cache 0.14.0 2019-12-06 [1] CRAN (R 4.0.3) #> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.0.3) #> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.0.3) #> R.utils 2.10.1 2020-08-26 [1] CRAN (R 4.0.3) #> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.3) #> rappdirs 0.3.1 2016-03-28 [1] CRAN (R 4.0.3) #> rematch2 2.1.2 2020-05-01 [1] CRAN (R 4.0.3) #> reprex 0.3.0.9001 2020-10-25 [1] Github (tidyverse/reprex@d3fc4b8) #> rlang 0.4.8 2020-10-08 [1] CRAN (R 4.0.3) #> rmarkdown 2.5.3 2020-11-04 [1] Github (rstudio/rmarkdown@bb7d952) #> sass 0.2.0.9005 2020-11-04 [1] Github (rstudio/sass@fef1d25) #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.3) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.3) #> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.3) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.3) #> styler 1.3.2 2020-02-23 [1] CRAN (R 4.0.3) #> tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.3) #> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.3) #> vctrs 0.3.4 2020-08-29 [1] CRAN (R 4.0.3) #> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.3) #> xfun 0.19.3 2020-11-06 [1] Github (yihui/xfun@12e77f5) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.3) #> #> [1] C:/Program Files/R/R-4.0.3/library
rich-iannone commented 3 years ago

Thanks @jooyoungseo ! I'll definitely get this change made soon when I start on the accessibility pass. If you find any more aspects of HTML tables that are suboptimal for accessibility, please file those as issues as well.

jooyoungseo commented 3 years ago

Thanks, @rich-iannone! I have found some more that I will also file soon.

What about we create a new label "Accessibility" to easily track down?

rich-iannone commented 3 years ago

I was just thinking that! I'll make that label and apply it to this issue (and previous ones).

rich-iannone commented 2 years ago

Now that https://github.com/rstudio/gt/pull/979 is merged, I'm closing this issue.