避免仅在R数据表的第一列中换行 [英] Avoid Wrapping Text only in first column of R datatable

查看:66
本文介绍了避免仅在R数据表的第一列中换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力避免将数据表中的一列文字换行。

I'm struggling with keeping text in one column of a datatable from wrapping.

我想避免在第一列中换行(因为这是使行大小变大的唯一部分),但应将选项保留在标题中(以避免滚动) )。

I'd like to avoid wrapping text in the first column (as it's the only part that makes the row size bigger), but keep the option in the headers (to avoid having to scroll).

我尝试过调整第一列的宽度,但是无论使用什么尺寸,文本都会不断换行。

I've tried adjusting the width of the first column, but the text keeps wrapping no matter what size I use.

DT::datatable(chartfilter,
    rownames = FALSE,
    options=list(iDisplayLength=7,                    
                 bPaginate=FALSE,                  
                 bLengthChange=FALSE,                       
                 bFilter=FALSE,                                    
                 bInfo=FALSE,
                 rowid = FALSE,
                 autoWidth = FALSE,
                 ordering = FALSE,
                 scrollX = TRUE,
                 columnDefs = list(list(width='500px', targets = list(1)))

我还找到了一种解决方案,可以关闭文本换行在整个表格中-但我不想在我的列标签中使用。将此添加到表输出前面的UI中:

I've also found a solution that turns text wrapping off in the entire table - but I don't want that for my column labels. Adding this in the UI in front of the tableoutput:

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

这是否可行,还是我只需要接受将文本换行第一栏?感谢我可以获得的任何帮助,并告诉我是否需要更多信息。

Is this possible, or do I just have to accept wrapping text in the first column? Appreciate any help I can get, and let me know if more info is needed.

推荐答案

使用 formatStyle()函数将特定样式应用于列:

Use the formatStyle() function to apply a specific style to a column:

datatable() %>% formatStyle("Region","white-space"="nowrap")

此函数来自相同的库(DT)。有关 formatStyle()的更多信息,请参见: https://rstudio.github.io/DT/010-style.html

This function comes from the same library (DT). More info on formatStyle() can be found here: https://rstudio.github.io/DT/010-style.html

这篇关于避免仅在R数据表的第一列中换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆