【问题标题】:R reactable _ how to truncate cell content and display upon hovering?R reactable _如何截断单元格内容并在悬停时显示?
【发布时间】:2021-02-11 21:46:42
【问题描述】:

我在表格中有一些长文本,我显示为可反应。我希望长文本被截断,并且仅在悬停在其顶部时出现。到目前为止,我已经设法截断单元格中的文本,但我无法使悬停工作。有什么帮助吗?

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")
          )
        )```

【问题讨论】:

    标签: javascript html r reactable


    【解决方案1】:

    使用tippy的解决方法:

    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)}
                      )
                    ))
    

    【讨论】:

    • 这是一个很好的解决方案。但是,这似乎不适用于嵌套表(嵌套中的内部表)。
    猜你喜欢
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多