r - DT 数据表中的列对齐

标签 r shiny dt

在我的 shiny我正在使用的应用程序 datatable函数来自 DT库来构建表格并希望在中心对齐列。我可以用 formatStyle('column', textAlign = 'center')但它只影响列正文而不影响标题。

最佳答案

我们必须设置columnDefs在论证中 option功能datatable .
请参阅下面的示例:

library(DT)

datatable(head(iris),
          rownames = FALSE,
          options = list(
            columnDefs = list(list(className = 'dt-center', targets = 0:4))
            )
          )
我们必须设定目标。在示例中,所有 5 列都对齐到“中心”( targets = 0:4 )。
最后,请注意列号从 0 开始,而不是从 1 开始。
注:我们可以使用 targets="_all"无论列数如何,都适用于所有列。

关于r - DT 数据表中的列对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35749389/

相关文章:

r - 在R中使用nls重新创建研究

r - 带有基于顺序的数字的分类列的前缀标签

r - 当 DataExplorer::plot_str() 调用时,其他图消失

r - Shiny + DT : Single Cell Selection

r - 在 DataTable 输出中使用 Shiny 输入

r - 数据表 R 中的调色板

R 数据表按钮导出格式化单元格

javascript - 将 Shiny 的reactive()值传递到DT的javascript部分

r - ggvis 将 ":= "与 data.table 结合使用

javascript - 需要替换 Shiny R renderDataTable 中的默认 "No data available in table"消息