在 R 四开本文档中使用 `kableExtra` 生成的表格中添加工具提示或弹出窗口

问题描述 投票:0回答:1

我想向 Quarto 中的 HTML 表格添加工具提示或弹出窗口,但在阅读文档并进行大量试验和错误后,我陷入了困境。链接按预期工作,但工具提示或弹出消息不显示。

文件foo.qmd

---
format: html
---


<script>
$(document).ready(function(){
    $('[data-toggle="popover"]').popover(html: true); 
});
</script>


```{r}
library(kableExtra)
library(dplyr)
library(tibble)

## example data
dt <- mtcars[1:6, 1:3] |>
  rownames_to_column(var = "car") |>
  remove_rownames() |>
  mutate(link="link")

POP  <- paste("lorem ipsum", LETTERS[1:6])
LINK <- paste0("https://example.org/page",1:6,".html")

dt |>
  mutate(car  = cell_spec(car, "html", popover = spec_popover(content=POP)),
         link = cell_spec(LINK, "html", link=LINK)) |>
  kbl(format = "html", escape = FALSE)
```

r knitr quarto kableextra
1个回答
0
投票

改变你的汽车变异有用吗?

mutate(car = text_spec(car, "html", tooltip=POP), 链接 = cell_spec(LINK, "html", link=LINK))

sample

library(kableExtra)
library(dplyr)
library(tibble)

## example data
dt <- mtcars[1:6, 1:3] |>
  rownames_to_column(var = "car") |>
  remove_rownames() |>
  mutate(link="link")

POP  <- paste("lorem ipsum", LETTERS[1:6])
LINK <- paste0("https://example.org/page",1:6,".html")

dt |>
  mutate(car  = text_spec(car, "html", tooltip=POP),
         link = cell_spec(LINK, "html", link=LINK)) |>
  kbl(format = "html", escape = FALSE)
© www.soinside.com 2019 - 2024. All rights reserved.