首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R reactable _如何截断单元格内容并在悬停时显示?

R reactable _如何截断单元格内容并在悬停时显示?
EN

Stack Overflow用户
提问于 2020-10-29 20:39:56
回答 1查看 201关注 0票数 2

我在一个表格中有一些很长的文本,我将其显示为可访问的。我希望长文本被截断,只有当悬停在它上面时才会出现。到目前为止,我已经设法截断了单元格中的文本,但我无法使悬停起作用。有什么帮助吗?

代码语言:javascript
复制
library(reactable)
library(tidyverse)

reactable(
      iris[1:5, ] %>% mutate(Species = 'This text is long and should only show up entirely when hovering'),
      columns = list(
        Species = colDef(
          html = TRUE,
          style = "
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          hover: visible")
          )
        )```
EN

回答 1

Stack Overflow用户

发布于 2020-10-30 20:15:37

使用tippy的解决方法:

代码语言:javascript
复制
library(shiny)
library(tippy)
library(reactable)
library(tidyverse)

render.reactable.cell.with.tippy <- function(text, tooltip){
  div(
    style = "text-decoration: underline;
                text-decoration-style: dotted;
                text-decoration-color: #FF6B00;
                cursor: info;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;",
    tippy(text = text, tooltip = tooltip)
  )
}

data <-  iris[1:5,] %>%
        mutate(Species = 'This text is long and should only show up entirely when hovering') %>%
        select(Species, everything())
      
      reactable(data,
                columns = list(
                  Species = colDef(
                    html = TRUE,
                    cell =  function(value, index, name) {
                      render.reactable.cell.with.tippy(text = value, tooltip = value)}
                  )
                ))
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64591293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档