-
Notifications
You must be signed in to change notification settings - Fork 27
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
Two column layout with high level header #117
Two column layout with high level header #117
Conversation
I forgot to add this uses xml2 to extract styling information from raw gt html. xml2 is already listed in Suggests but I think it's a strong reverse dependency anyway. |
There is also room for improvements here. For example high level title and table level subtitles. |
gt_subtitle <- raw_html %>% | ||
xml2::xml_find_first("//*[contains(concat(' ',normalize-space(@class),' '),' gt_subtitle ')]") | ||
|
||
gt_table_id <- raw_html %>% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gt writes the table id into the selectors of the stylesheet. We extract that id here to replace it with our own id in the next step.
xml2::xml_find_first("//style") %>% | ||
xml2::xml_contents() %>% | ||
xml2::xml_text() %>% | ||
gsub(gt_table_id, "mycombinedtable", x = .) %>% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is necessary to apply the style to our top level heading
xml2::xml_contents() %>% | ||
xml2::xml_text() %>% | ||
gsub(gt_table_id, "mycombinedtable", x = .) %>% | ||
gsub("mycombinedtable table", "mycombinedtable div", x = .) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table selector sets font. Since we put the header in div tags we replace table with div in the style sheet.
|
||
xml_missing <- function(xml){ | ||
xml_txt <- xml2::xml_text(xml) | ||
if (is.na(xml_txt)) return(NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xml2 returns NA
if the text is missing. We return NULL
to drop it entirely from the html.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mrcaseb ! Going to merge and then we can iterate
This is a more or less special feature I see people asking for in the nflverse discord. The main idea is to allow a high level tab header in the two column layout.
The problem here is formatting. We can either ask the user to set all the html styles themselves or try to help via gt. So in this PR, the function extracts tab header information (including all of the styling) from the header of one of the two tables. This allows the user to do all of the styling through gt.
Example
Current implementation
With Header