寻找一种漂亮的方法来为包含大量文本的列创建可扩展的行

发布于 2025-01-09 06:16:11 字数 1736 浏览 1 评论 0原文

我希望制作一个具有可扩展行的表,这些行在切换时可以保持打开状态。

我想将包含大量文本的列作为可扩展的行详细信息。问题是,当我在可反应中使用“详细信息”来扩展该列时,该列太宽以至于超出屏幕,难以阅读。有没有办法限制可扩展行的最大宽度,使其仅在列所在位置附近扩展?

library(reactable)
library(tidyverse)
library(shiny)
library(tippy)

library(htmltools)
library(webshot)
library(htmlwidgets)

iris2 <- cbind(USArrests[1:32,], mtcars, iris[1:32,])

data2 <-  iris2 %>%
  mutate(Species = 'This text is long and should only show up entirely when hovering because it is making the shape of my table ugly
                    and difficult to read when expanded. This text is long and should only show up entirely when hovering because it 
                      is making the shape of my table ugly and difficult to read when expanded.This text is long and should only show
                      up entirely when hovering because it is making the shape of my table ugly and difficult to read when expanded. 
                      This text is long and should only show up entirely when hovering because it is making the shape of my table ugly 
                      and difficult to read when expanded.') 

data <- data2 %>% mutate(Species = word(data2$Species, start =1, end=8, sep = fixed(" ")))

dog2 <- reactable( data,
                   columns = list(
                     Species = colDef(details = function(index) {
                       paste(data2[index, "Species"])
                     })),
                   striped = TRUE,
                   bordered = TRUE)

saveWidget(dog2, "test.html")

任何帮助将不胜感激!谢谢你!

(我发现这个问答很有帮助,但仍然希望有可扩展的行,而不必悬停 R 可反应_如何截断单元格内容并在悬停时显示?

I was hoping to make a table that has expandable rows that may stay open when toggled.

I wanted to put the columns with long amounts of text as expandable row details. The problem is when I use "details" in reactable to expand that column it's so wide that it goes off-screen making it hard to read. Is there a way to limit the max-width of the expandable row so it only expands approximately where the column is located?

library(reactable)
library(tidyverse)
library(shiny)
library(tippy)

library(htmltools)
library(webshot)
library(htmlwidgets)

iris2 <- cbind(USArrests[1:32,], mtcars, iris[1:32,])

data2 <-  iris2 %>%
  mutate(Species = 'This text is long and should only show up entirely when hovering because it is making the shape of my table ugly
                    and difficult to read when expanded. This text is long and should only show up entirely when hovering because it 
                      is making the shape of my table ugly and difficult to read when expanded.This text is long and should only show
                      up entirely when hovering because it is making the shape of my table ugly and difficult to read when expanded. 
                      This text is long and should only show up entirely when hovering because it is making the shape of my table ugly 
                      and difficult to read when expanded.') 

data <- data2 %>% mutate(Species = word(data2$Species, start =1, end=8, sep = fixed(" ")))

dog2 <- reactable( data,
                   columns = list(
                     Species = colDef(details = function(index) {
                       paste(data2[index, "Species"])
                     })),
                   striped = TRUE,
                   bordered = TRUE)

saveWidget(dog2, "test.html")

Any help would be much appreciated! Thank you!

(I found this Q and A to be helpful however was still hoping for expandable rows instead of having to hover R reactable _ how to truncate cell content and display upon hovering? )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文