【问题标题】:keeping same height of row for DT table in output在输出中保持 DT 表的行高相同
【发布时间】:2021-05-24 09:21:49
【问题描述】:

我想为 DT 表输出设置行常量或固定的高度。对于下表,您可以看到行高的差异。

所以这种情况是当字符数增加时,例如在这种情况下,在第一个列中的第二行,那么所有行的高度都应该调整为相同。

df <- data.frame(`quote` = c("the trader belongs to","trader have long ralationship withthe same market with my opinion on thaw its implemented mmnnhhh sdfghj fghj kjhgf tyui cvbnm",
                             "types of trads happens everytime when market slow","trades have leverage with",
                             "market is continious with the same platform trades"),
                 `share`= c(43,65,92,23,73),
                 `times` = c(86,98,55,12,08),
                 `parts`=c(4,7,4,8,3))


df<-datatable(df,
              options = list(columnDefs = 
                               list(list(className = 'dt-center', 
                                         targets = "_all"))),rownames = FALSE)
df

就像在 flextable 中一样,我可以执行以下操作,但要为 DT 表寻找固定解决方案或任何功能。

(ncols %in% c(4,5)) {
    fl<-width(flxtable, width = d*0.3, j = 1)
    fl<-width(flxtable, width = (d*0.7)/(ncols-1), j = 2:ncols)
d is left and right margin of docs template

【问题讨论】:

    标签: r dt


    【解决方案1】:

    我过去在这方面取得了成功:

    DT::datatable(df) %>%
    DT::formatStyle(names(df),lineHeight='80%') 
    

    感谢帮助我的帖子,但我现在找不到它了。

    【讨论】:

    • 如果字符的长度增加,这仍然不起作用,那么这又是一样的,行的高度增加了。
    • 这是要付出代价的。如果您的字符串是“长”并且不适合一行,它将中断。根据列宽,这可能会导致多个“行”。这甚至适用于flextable - 但我假设您的尺寸使高度看起来相同。对于 DT,我建议查看文档:rstudio.github.io/DT/options.html 4.4。显示截断字符串以使其适合列的示例。不适合列的部分将显示为工具提示。虽然不是“固定”高度,但您可以使用要显示的字符串长度和列宽。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多