rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
2.04k stars 210 forks source link

zero width table created #1532

Open cderv opened 10 months ago

cderv commented 10 months ago

Quarto example (without bootstrap)

---
title: "Test"
format: 
  html:
    theme: pandoc
keep-md: true
---

## Toto
```{r}
library(magrittr)
library(gt)

Tata

iris %>%
  gt() %>%
  cols_width(
    "Sepal.Length" ~ px(300),
    everything() ~ px(50)
  ) %>%
  as_raw_html()

The HTML table created by **gt** has a `width: 0` in style
````html
  <table class="gt_table" style="-webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; table-layout: fixed; width: 0px;" data-quarto-disable-processing="false" data-quarto-bootstrap="false" width="0" bgcolor="#FFFFFF">

Also width= attribute is set (which is deprecated I believe).

Not sure from where this zero 0 width is coming.

Reported first at https://github.com/quarto-dev/quarto-cli/issues/8233

cderv commented 10 months ago

It could be on purpose though - I don't know gt a lot.

This is an issue with Quarto processing activated in fact (if you opt out) table is visible) because Quarto processing will not keep

<colgroup>
    <col style="width:300px;">
    <col style="width:50px;">
    <col style="width:50px;">
    <col style="width:50px;">
    <col style="width:50px;">
  </colgroup>

And I see this following this hint: https://github.com/rstudio/gt/blob/55e3d6a0bb9838cef110658b28ff703ef0ec80e5/R/utils_render_html.R#L280-L310

Considering colgroup is a specific feature opt-in by user https://github.com/rstudio/gt/blob/55e3d6a0bb9838cef110658b28ff703ef0ec80e5/R/utils_render_html.R#L256

maybe column width is set Quarto processing should be disabled ? or a warning thrown ? Because I don't think quarto will respect the column

olivroy commented 2 months ago

See https://github.com/rstudio/gt/pull/1873#issuecomment-2327271585 for the explanation of why this is