【问题标题】:Prevent column name wrap in shiny DataTable防止列名在闪亮的 DataTable 中换行
【发布时间】:2015-09-26 09:54:48
【问题描述】:

我有一个闪亮的 DataTable(包“DT”),它有很长的列名(+ 空格),我想在没有名称包装的情况下呈现它 - 即 colnames 包裹在 2-3 行上。我启用了水平滚动来尝试并促进这一点:

renderDataTable(dataframe_with_long_colnames, ..., options = list(scrollX = TRUE))

但默认情况下,空格会折叠成新行。

我认为这回答了我的问题: https://www.datatables.net/forums/discussion/8923/how-do-you-stop-the-header-from-wrapping-into-multiple-rows 但我不确定如何将其转换为 R 函数。

此外,这里列出了所有 DataTable 选项:https://www.datatables.net/reference/option/

提前致谢。

【问题讨论】:

    标签: jquery r datatables shiny dt


    【解决方案1】:

    在 ui.R 中,在呈现表格的行之前添加以下行:

    tags$head(tags$style("#table1  {white-space: nowrap;  }")),
    

    table1 替换为xxxxxserver.R 文件中的输出语句中

    output$`xxxxx`<-renderDataTable(.....
    

    【讨论】:

    • 好答案 - 谢谢!就我而言,已经定义了 tags$head,所以我只需要提供:“tags$style(HTML('#current_data{white-space:nowrap}'))” - 不要忘记 '#'!
    【解决方案2】:

    您可以简单地使用nowrap 类:

    library(DT)
    
    dat <- data.frame(
      "This is a looooooooooooooooonnnnnnnnnnnnggggggg column name" = c(1,2),
      "This is also a looooooooooooooooooonnnnnnnnnnnggggggg column name" = c(3,4),
      check.names = FALSE
    )
    
    datatable(dat, class = "display nowrap")
    

    【讨论】:

      猜你喜欢
      • 2016-02-09
      • 2014-10-02
      • 2020-02-04
      • 1970-01-01
      • 2016-10-18
      • 2020-01-18
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      相关资源
      最近更新 更多