gt icon indicating copy to clipboard operation
gt copied to clipboard

[quarto] tables with `fmt_markdown` don't render in quarto dashboard

Open jburos opened this issue 1 year ago • 2 comments

Prework

Description

I have a quarto dashboard, converted from an html file, in which some but not all gt tables fail to render. I was able to isolate the behavior only to those tables using fmt_markdown. In all my exmaples, the markdown string includes a <br/>. I'm not sure if this extends to other contents.

Reproducible example

  • [x] Post a minimal reproducible example so the maintainer can troubleshoot the problems you identify. A reproducible example is:
    • [x] Runnable: post enough R code and data so any onlooker can create the error on their own computer.
    • [x] Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
    • [x] Readable: format your code according to the tidyverse style guide.
---
title: "test-gt-markdown"
format: dashboard
---

# with markdown

## row

```{r}
#| title: with markdown
library(gt)
library(dplyr)
library(glue)
h <- head(sp500, n = 3) |> 
  mutate(test = glue::glue('{LETTERS[row_number()]}<br/>test')) |>
  gt() |>
  fmt_markdown(columns = c(test))
h
```

# session

```{r}
sessioninfo::session_info()
```
Screenshot 2024-03-11 at 3 52 25 PM

Expected result

I expected the table to render within the card. Instead, the rendered document is blank.

Session info

I'm using quarto version: 1.4.551

sessioninfo::session_info()

─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.2 (2023-10-31)
 os       macOS Sonoma 14.3
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/New_York
 date     2024-03-11
 pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 cli           3.6.2   2023-12-11 [1] CRAN (R 4.3.1)
 commonmark    1.9.1   2024-01-30 [1] CRAN (R 4.3.1)
 digest        0.6.34  2024-01-11 [1] CRAN (R 4.3.1)
 dplyr       * 1.1.4   2023-11-17 [1] CRAN (R 4.3.1)
 evaluate      0.23    2023-11-01 [1] CRAN (R 4.3.1)
 fansi         1.0.6   2023-12-08 [1] CRAN (R 4.3.1)
 fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.3.0)
 generics      0.1.3   2022-07-05 [1] CRAN (R 4.3.0)
 glue          1.7.0   2024-01-09 [1] CRAN (R 4.3.1)
 gt          * 0.10.1  2024-01-17 [1] CRAN (R 4.3.1)
 htmltools     0.5.7   2023-11-03 [1] CRAN (R 4.3.1)
 htmlwidgets   1.6.4   2023-12-06 [1] CRAN (R 4.3.1)
 jsonlite      1.8.8   2023-12-04 [1] CRAN (R 4.3.1)
 knitr         1.45    2023-10-30 [1] CRAN (R 4.3.1)
 lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.3.1)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.3.0)
 markdown      1.12    2023-12-06 [1] CRAN (R 4.3.1)
 pillar        1.9.0   2023-03-22 [1] CRAN (R 4.3.0)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.3.0)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.3.0)
 rlang         1.1.3   2024-01-10 [1] CRAN (R 4.3.1)
 rmarkdown     2.26    2024-03-05 [1] CRAN (R 4.3.1)
 rstudioapi    0.15.0  2023-07-07 [1] CRAN (R 4.3.0)
 sass          0.4.8   2023-12-06 [1] CRAN (R 4.3.1)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.3.0)
 tibble        3.2.1   2023-03-20 [1] CRAN (R 4.3.0)
 tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.3.0)
 utf8          1.2.4   2023-10-22 [1] CRAN (R 4.3.1)
 vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.3.1)
 withr         3.0.0   2024-01-16 [1] CRAN (R 4.3.1)
 xfun          0.42    2024-02-08 [1] CRAN (R 4.3.1)
 xml2          1.3.6   2023-12-04 [1] CRAN (R 4.3.1)
 yaml          2.3.8   2023-12-11 [1] CRAN (R 4.3.1)

 [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library

──────────────────────────────────────────────────────────────────────────────

jburos avatar Mar 11 '24 19:03 jburos

I would like to note that using md() for changing cols_label() yields the same behavior, and that it works as expected with gt 0.10.0.

---
title: "dash-test"
format: dashboard
editor: visual
editor_options: 
  chunk_output_type: console
---

## Heading

```{r}
#| title: a title0
library(gt)
exibble |> 
 gt::gt() |>
  cols_label(
    num = md("**here**")
  )
```

I tested that the example provided by OP doesn't work in gt 0.11 + Quarto 1.4.554 (have to check for 1.4.555 + 1.5)

olivroy avatar May 13 '24 13:05 olivroy

I can confirm this is a Quarto issue.

Though @rich-iannone using <span data-qmd instead of <div data-qmd avoid the issue.

Maybe not using div always could be a good idea. Also content is duplicated like this

<div data-qmd="**here**"><div class='gt_from_md'><p><strong>here</strong></p>
</div></div>

and this will create two entry in the table. But maybe this is a Quarto issue, as the content of the div should probably be ignored when processed 🤔

i'll look into it

cderv avatar May 17 '24 16:05 cderv

@jburos Now that Quarto 1.5 is released, it is recommended to update to this version.

Your example renders correctly with Quarto 1.5

  • https://github.com/quarto-dev/quarto-cli/issues/9696
  • https://github.com/quarto-dev/quarto-cli/issues/9939

olivroy avatar Jul 03 '24 15:07 olivroy

Yes I believe we fixed it on Quarto side. @rich-iannone I think this is ok now, also following our last discussion

cderv avatar Jul 04 '24 10:07 cderv