rstudio / gt

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

`opt_interactive()` makes `tab_footnote()` footnote marks disappear #1905

Open xx02al opened 4 days ago

xx02al commented 4 days ago

when using opt_interactive(), tab_footnote() footnote marks disappear

gt_base <- iris |>
  gt::gt() |>
  gt::tab_footnote(
    footnote = "a footnote",
    locations = gt::cells_body(
      columns = Sepal.Length, 
      rows = Sepal.Length > 5
    ),
    placement = "right"
  )

# works
gt_base

# footnote marks disappear
gt_base |> 
  gt::opt_interactive()
olivroy commented 4 days ago

This is because we don't fully build the table for performance.

We'll see how we address this, but as a workaround, you can use the following.

gt_base <- iris |>
    gt::gt() |>
    gt::tab_footnote(
        footnote = "a footnote",
        locations = gt::cells_body(
            columns = Sepal.Length, 
            rows = Sepal.Length > 5
        ),
        placement = "right"
    )

# works
gt_base

# footnote appears
gt_base |> 
    gt::opt_interactive() |> fmt_number(Sepal.Length)

image

xx02al commented 4 days ago

this workaround works as long as columns is numeric, i.e., this workaround has very limited applicability. taking the above example, using e.g., columns = c(Sepal.Length, Species) illustrates it would be valuable to have a proper solution