Skip to content

Commit

Permalink
Merge pull request #1711 from olivroy/rowname
Browse files Browse the repository at this point in the history
fix usage of `rowname_col` for `opt_interactive()`
  • Loading branch information
rich-iannone authored Jun 18, 2024
2 parents 64c253f + 7df5f6d commit b457ff3
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions R/render_as_i_html.R
Original file line number Diff line number Diff line change
@@ -122,6 +122,18 @@ render_as_ihtml <- function(data, id) {

#nocov end

rownames_to_stub <- stub_rownames_has_column(data)
# use of special .rownames doesn't work.
# Workaround https://github.com/glin/reactable/issues/378
# rstudio/gt#1702
if (rownames_to_stub) {
rowname_col <- dt_boxhead_get_var_stub(data)
if (length(rowname_col) == 1) {
# avoid base R error when setting duplicate row names.
attr(data_tbl, "row.names") <- as.character(data$`_data`[[rowname_col]])
}
}

# Obtain column label attributes
column_names <- dt_boxhead_get_vars_default(data = data)
column_labels <- dt_boxhead_get_vars_labels_default(data = data)
@@ -183,8 +195,6 @@ render_as_ihtml <- function(data, id) {
column_labels_border_bottom_width <- opt_val(data = data, option = "column_labels_border_bottom_width")
column_labels_border_bottom_color <- opt_val(data = data, option = "column_labels_border_bottom_color")

rownames_to_stub <- stub_rownames_has_column(data)

emoji_symbol_fonts <-
c(
"Apple Color Emoji", "Segoe UI Emoji",
9 changes: 9 additions & 0 deletions tests/testthat/test-i_html.R
Original file line number Diff line number Diff line change
@@ -68,6 +68,13 @@ test_that("Interactive tables won't fail when using different options", {
tab_source_note(source_note = "Source Note.") %>%
tab_footnote(footnote = "Footnote.") %>%
opt_interactive()
# #1702
tbl_gt_i_23 <-
gt(exibble, rownames_to_stub = TRUE) %>%
opt_interactive()
tbl_gt_i_24 <-
gt(mtcars_short, rowname_col = "vs") %>%
opt_interactive()

capture_output(expect_no_error(tbl_gt_i_01))
capture_output(expect_no_error(tbl_gt_i_02))
@@ -91,4 +98,6 @@ test_that("Interactive tables won't fail when using different options", {
capture_output(expect_no_error(tbl_gt_i_20))
capture_output(expect_no_error(tbl_gt_i_21))
capture_output(expect_no_error(tbl_gt_i_22))
capture_output(expect_no_error(tbl_gt_i_23))
capture_output(expect_no_error(tbl_gt_i_24))
})

0 comments on commit b457ff3

Please sign in to comment.