gt icon indicating copy to clipboard operation
gt copied to clipboard

opt_interactive adds unwanted tab_spanner rules

Open wgrundlingh opened this issue 10 months ago • 0 comments

Description

Additional spanner lines are added to columns that don't have a spanner title when the interactive form of a gt table is generated.

Reproducible example

The following example prints a spanner and horizontal rule covering cyl, disp and hp from mtcars:

library(tidyverse)
library(gt)

mtcars %>%
  slice_head(n = 10) %>% 
  gt() %>% 
  tab_spanner(
    label = 'Engine',
    columns = c(cyl, disp, hp)
  )

Here is a visual of the output:

Image

If we add opt_interactive() in the pipeline, the spanner rules are not as clear:

library(tidyverse)
library(gt)

mtcars %>%
  slice_head(n = 10) %>% 
  gt() %>% 
  tab_spanner(
    label = 'Engine',
    columns = c(cyl, disp, hp)
  ) %>% 
  opt_interactive()

Image

At first glance, the spanner rules now span the entire table horizontally. A mild separation between the requested and additional spanner rule is visible. But it's nearly invisible, making the spanner rule useless.

Expected result

I'd expect the horizontal rules under the opt_interactive() interface to match that without the interactive option active. Moreover, the loss of continuity in the display makes the spanner not helpful.

Session info

R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8   
[3] LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.utf8    

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] gt_0.11.1       lubridate_1.9.4 forcats_1.0.0   stringr_1.5.1  
 [5] dplyr_1.1.4     purrr_1.0.4     readr_2.1.5     tidyr_1.3.1    
 [9] tibble_3.2.1    ggplot2_3.5.1   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.9    gtable_0.3.6      compiler_4.4.1    tidyselect_1.2.1 
 [5] xml2_1.3.6        snakecase_0.11.1  scales_1.3.0      yaml_2.3.10      
 [9] fastmap_1.2.0     R6_2.5.1          generics_0.1.3    htmlwidgets_1.6.4
[13] janitor_2.2.1     munsell_0.5.1     reactable_0.4.4   pillar_1.10.1    
[17] tzdb_0.4.0        rlang_1.1.5       stringi_1.8.4     reactR_0.6.1     
[21] sass_0.4.9        timechange_0.3.0  cli_3.6.3         withr_3.0.2      
[25] magrittr_2.0.3    crosstalk_1.2.1   digest_0.6.37     grid_4.4.1       
[29] rstudioapi_0.17.1 hms_1.1.3         lifecycle_1.0.4   vctrs_0.6.5      
[33] glue_1.8.0        colorspace_2.1-1  tools_4.4.1       pkgconfig_2.0.3  
[37] htmltools_0.5.8.1

wgrundlingh avatar Feb 20 '25 23:02 wgrundlingh