Creating a Quarto table with HTML links in for Google Drive

Howdy folks! I think I've found an issue in the Quarto renderer, but I'd like to make sure I'm not missing something before I open an issue.

The goal is to have a doc on Google Drive (so, DOCX output from Quarto) containing a table which has HTML links in one of the columns. I can get this to work for other formats, and in RStudio, but the DOCX files only work if I export the tables to a separate file - the renderer report fails to contain HTML. This happens with both gt and flextable so I think it's Quarto rather than either of those packages.

To illustrate, here's a short(ish) qmd file which makes a suitable table, saves it, and then renders it:

Quarto doc code
---
title: "Table URL Reprex"
author:
  - name: Greg Sutcliffe
date: "`r Sys.Date()`"
format: docx
---

Rendering a table containing HTML seems to fail in DOCX format, while saving to a file works.

## Dataset

```{r}
df <- tibble::tibble(
  text = c("Google", "DuckDuckGo", "Bing"),
  url  = c( "https://google.com", "https://duckduckgo.com", "https://bing.com")
)
```

## GT Table
Make a `gt` table using `fmt_markdown` (`fmt_url` doesnt seem to work at all with DocX) - works if saved to a file, but not when rendered
```{r}
library(gt)

gtab <- df |>
  dplyr::mutate(url = glue::glue("[{url}]({url})")) |>
  gt() |>
  fmt_markdown(columns = url)

gtsave(gtab, 'gt.docx','/tmp/')

gtab
```

## Flextable

Similiarly, `flextable` works when saved but not when rendered:

```{r}
library(flextable)

ftab <- df |>
  flextable() |>
  mk_par(
    j = "url",
    value = as_paragraph(
      hyperlink_text(
        x = url, url = url, props = fp_text_default(color='blue')
      )
    )
  )

  save_as_docx(ftab, path='/tmp/ft.docx')

ftab
```

Neither rendered table works in LibreOffice or in Google Drive, but both exported files do.

This creates reprex.docx, gt.docx and ft.docx. If I upload the files to GDrive, then I can get some sceenshots:

Firstly, the rendered doc, which you can see has the raw URL text and style, but the the links are missing:


But the exported/saved files do work:


ft.docx

Am I missing some way to tell Quarto to render these properly when part of a code chunk? Or have a found a bug here?

Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Out of curiosity I tried in R Markdown directly and it does not seem to work either.

---
title: "Table URL Reprex"
author:
  - name: Greg Sutcliffe
date: "`r Sys.Date()`"
output: word_document
---

Rendering a table containing HTML seems to fail in DOCX format, while saving to a file works.

## Dataset

```{r}
df <- tibble::tibble(
  text = c("Google", "DuckDuckGo", "Bing"),
  url  = c( "https://google.com", "https://duckduckgo.com", "https://bing.com")
)
```

## GT Table

Make a `gt` table using `fmt_markdown` (`fmt_url` doesnt seem to work at all with DocX) - works if saved to a file, but not when rendered
```{r}
library(gt)

gtab <- df |>
  dplyr::mutate(url = glue::glue("[{url}]({url})")) |>
  gt() |>
  fmt_markdown(columns = url)

# gtsave(gtab, 'gt.docx','/tmp/')

gtab
```

## Flextable

Similiarly, `flextable` works when saved but not when rendered:

```{r}
library(flextable)

ftab <- df |>
  flextable() |>
  mk_par(
    j = "url",
    value = as_paragraph(
      hyperlink_text(
        x = url, url = url, props = fp_text_default(color='blue')
      )
    )
  )

  # save_as_docx(ftab, path='/tmp/ft.docx')

ftab
```

Neither rendered table works in LibreOffice or in Google Drive, but both exported files do.

So it does not seem to be quarto, but rather Pandoc directly or just gt and flextable are not emitting the right openxml content for a table link to be correctly created.

It could be an issue in those package, or with Pandoc processing the openxml :thinking:

Could you try opening an issue in gt if none already ?

cc @rich_i