I created a data.frame that I would like to show as a table:
df <- data.frame(A=c("a","b"),
B=c("[link](http://stackoverflow.com)","[link](http://stackoverflow.com)"))
Now I would like to display it and have the links show. This works fine:
kable(df,format="html",escape=FALSE)
However, now I would like to collapse the column with the links, I use collapse_rows
but then the links themselves don't work anymore:
kable(df,format="html",escape=FALSE) %>% collapse_rows(columns=2)
This is an example complete reproducible quarto document, I put # on the {r} and
marks in the code as it would mess up the layout otherwise:
---
title: "Test"
format: html
editor: visual
---
#```{r}
#| echo: true
df <- data.frame(A=c("a","b"),B=c("[link](http://stackoverflow.com)","[link](http://stackoverflow.com)"))
library(knitr)
library(kableExtra)
kable(df,format="html",escape=FALSE) %>% collapse_rows(columns=2)
#```
You can use a HTML link for your column B and it will work
---
title: "Test"
format: html
editor: visual
---
```{r}
#| echo: true
df <- data.frame(
A = c("a","b"),
B = rep('<a href="http://stackoverflow.com" target="_blank">link</a>',2)
)
library(knitr)
library(kableExtra)
kable(df,format="html",escape=FALSE) %>% collapse_rows(columns=2)
```