gt icon indicating copy to clipboard operation
gt copied to clipboard

Feature - Suppress inclusion of the default gt CSS into the generated HTML both inline and in a style block

Open volodymyrprokopyuk opened this issue 2 years ago • 3 comments

I've asked the question https://stackoverflow.com/questions/68351340/gt-table-suppress-inclusion-of-the-default-gt-css-into-the-generated-html-both at StackOverflow, but it seems that there is no answer, as the requested feature is not yet implemented.

I replicate the question from StackOverflow here as it is a feature request.

Is it possible to completely suppress the automatic inclusion of the default gt CSS styles into the generated HTML code both inline and in a style block? I know that the as_raw_html(gt_Obj, inline_css = T) moves default gt CSS from the style block to the inline style attribute that could be useful for emails.

I want to completely suppress the default gt CSS inclusion from the HTML code as I want to style the raw HTML gt table with my custom external CSS. I'm looking for something like as_raw_html(gt_Obj, include_css = F)

Thank you!

volodymyrprokopyuk avatar Jul 13 '21 17:07 volodymyrprokopyuk

This is a good idea and definitely something we could include in as_raw_html().

rich-iannone avatar Jul 13 '21 17:07 rich-iannone

Just adding a plus one to this feature request. I'd been using v0.2.2 with R 3.6 but recently upgraded to R 4.1 and so reinstalling {gt} bumped me to v0.3.1. I previously had code in an Rmarkdown that used as_raw_htm(df, inline_css=FALSE) to provide a raw HTML table and was using an external CSS file to provide custom css for the gt_* classes. It'd be great if there was a way to suppress the style blocks and data-refs. I really like using {gt} for structuring table output, so it'd be great if there was a way to retain the gt_* classes but suppress inclusion of style blocks.

mattkerlogue avatar Sep 29 '21 13:09 mattkerlogue

I use gt to produce internal reports with hundreds of static tables. The rendering time was huge, as well as the size of the final html, because the entire css was replicated for each table. I created a single external stylesheet and deleted the css for all the tables with something similar to this (inspired by @mattkerlogue solution at #858 ). Rendering time on Quarto and final file size have dropped dramatically.

remove_css <- function(x) {
  x <- gsub("<style>.*</style>", "", x)
  htmltools::HTML(x)
}

gtcars |> 
  gt() |> 
  as_raw_html(inline_css = FALSE) |>
  remove_css()

sauloguerra avatar Feb 14 '23 21:02 sauloguerra