Inconsistent Column Width Adjustment with `opt_interactive()`
Prework
- [x] Read and agree to the code of conduct and contributing guidelines.
- [x] If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
Description
Using opt_interactive(), if I try to change the columns width with cols_width(), the specified column's width does not change as expected. Instead, the width of the adjacent column is changed. The issue seems to occur only when rowname_col is passed to gt(). For example, in the code below using the gtcars data, adding cols_width(mfr ~ px(20)), the width of mfr doesn't change, but the width of year becomes 20px.
Moreover, it's possibly unrelated, but I also noticed that when rowgroups are present, opt_interactive() adds an extra empty column to the left of the table. Notice how, without opt_interactive(), the car's model is directly below the rowgroup header, while with opt_interactive() there is extra space.
Reproducible example
library(gt)
library(dplyr)
gtcars_short <- gtcars |>
group_by(ctry_origin) |>
slice_head(n = 1) |>
ungroup()
gtcars_short |>
gt() |>
cols_width(
"mfr" ~ px(20),
) |>
opt_interactive() |>
tab_header("Without rowname_col, all good")
gtcars_short |>
gt(rowname_col = "model") |>
cols_width(
"mfr" ~ px(20),
) |>
opt_interactive() |>
tab_header("With rowname_col, width of `year` changes instead of `mfr`")
gtcars_short |>
gt(rowname_col = "model", groupname_col = "year") |>
cols_width(
"mfr" ~ px(20),
) |>
tab_header("Without opt_interactive(), there is no extra space")
gtcars_short |>
gt(rowname_col = "model", groupname_col = "year") |>
cols_width(
"mfr" ~ px(20),
) |>
opt_interactive() |>
tab_header("With groupname_col, an extra empty column is added")
Expected result
I expected the width of the mfr column to change, but instead the width of year changed. The column that changes seems to always be the one next to the specified one. It looks like adding rownames with opt_interactive() causes an unintended shift of the columns to the left.
Session info
> sessionInfo()
R version 4.5.0 (2025-04-11)
Platform: x86_64-pc-linux-gnu
Running under: Arch Linux
Matrix products: default
BLAS: /usr/lib/libblas.so.3.12.0
LAPACK: /usr/lib/liblapack.so.3.12.0 LAPACK version 3.12.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: Europe/Berlin
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] webshot2_0.1.2 reprex_2.1.1 dplyr_1.1.4 gt_1.0.0
loaded via a namespace (and not attached):
[1] jsonlite_2.0.0 compiler_4.5.0 promises_1.3.2 Rcpp_1.0.14
[5] tidyselect_1.2.1 xml2_1.3.8 clipr_0.8.0 later_1.4.2
[9] jquerylib_0.1.4 callr_3.7.6 yaml_2.3.10 fastmap_1.2.0
[13] R6_2.6.1 tcltk_4.5.0 generics_0.1.4 knitr_1.50
[17] htmlwidgets_1.6.4 tibble_3.2.1 reactable_0.4.4 bslib_0.9.0
[21] pillar_1.10.2 rlang_1.1.6 websocket_1.4.4 utf8_1.2.5
[25] cachem_1.1.0 reactR_0.6.1 xfun_0.52 fs_1.6.6
[29] sass_0.4.10 cli_3.6.5 withr_3.0.2 magrittr_2.0.3
[33] ps_1.9.1 digest_0.6.37 processx_3.8.6 rstudioapi_0.17.1
[37] chromote_0.5.1 lifecycle_1.0.4 vctrs_0.6.5 evaluate_1.0.3
[41] glue_1.8.0 rmarkdown_2.29 tools_4.5.0 pkgconfig_2.0.3
[45] htmltools_0.5.8.1