Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML summary row styling fix #782

Merged
merged 5 commits into from
Jun 7, 2021
Merged

HTML summary row styling fix #782

merged 5 commits into from
Jun 7, 2021

Conversation

rich-iannone
Copy link
Member

A bug in the summary_row_tags() util function (in utils_render_html.R) can occasionally result in styles not being applied to certain summary rows. Issue #752 has an example where this is the case, and the first summary row does not have styling applied:

library(gt)
library(tidyverse)

tibble(
  div_num=c("630", "641", "643", "643", "646", "647"), 
  group_num=c("01","02","09","10","05","02"), 
  count=as.integer(c(1,1,1,1,8,2))
) %>% 
  group_by(div_num) %>% 
  gt(rowname_col = 'group_num') %>% 
  summary_rows(
    groups = TRUE,
    columns = vars(count),
    fns = list(`Division total: `="sum"),
    formatter = fmt_number,
    decimals = 0
  ) %>% tab_style(
    style = list(
      cell_text(
        weight = "bold",
        size = px(12)
      ),
      cell_fill("red")
    ),
    locations = cells_summary()
  ) 

The problem is traced to the statement in the summary_row_tags() function that resolves a decimal-based row number (rownum) to a whole number with ceiling((rownum %% 1) * 100). To fix the bug, the round() function should be used in place of ceiling().

Fixes: #752

@rich-iannone rich-iannone merged commit fef0da3 into master Jun 7, 2021
@rich-iannone rich-iannone deleted the html-summary-rows-fix branch June 7, 2021 19:16
rich-iannone added a commit that referenced this pull request Jun 7, 2021
* master:
  Add the `fmt_engineering()` and `fmt_integer()` formatter functions (#758)
  HTML summary row styling fix (#782)
  Refactor and improve rendering of title/subtitle components in HTML/LaTeX tables (#779)
rich-iannone added a commit that referenced this pull request Jun 11, 2021
* master: (24 commits)
  Fix for possible column name duplication when generating summary rows (#792)
  Change the `data` arg to `.data` to avoid partial matching issues (#772)
  Add the `force_sign` arg to several numeric formatters (#793)
  Add the `fmt_engineering()` and `fmt_integer()` formatter functions (#758)
  HTML summary row styling fix (#782)
  Refactor and improve rendering of title/subtitle components in HTML/LaTeX tables (#779)
  LaTeX bugfix for summary rows, and, implementation of grand summary rows (#768)
  Reinstate once failing test
  Include stub var in resolution of visible vars
  Use `seq_len()` instead of `seq()`
  Fix typo in README (#765)
  Increment version number (#762)
  Increase version number
  Documentation fixes (#759)
  Add missing topics to _pkgdown.yml
  Add `accounting` options for `fmt_percent()` and `fmt_number()` (#756)
  Simplify arguments for RTF page numbering
  Add the `fmt_bytes()` formatter function (#750)
  Simplify page numbering text
  Add testthat snapshot tests for RTF page numbering
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GT table not applying style to all summary rows
2 participants