如何更改 r shinydashboard 中数据表中列的对齐方式?

How to change alignment of columns in datatable in r shinydashboard?

我正在闪亮的仪表板中创建一个 dataTableOutput。默认情况下所有列都左对齐,我想将其更改为居中对齐。我在我的 server.R 文件中使用以下代码:

output$data<- renderDataTable({data()},
                            options = list(
                             columnDefs = list(list(className = 'dt-center', targets = '_all'))))

这段代码没有显示任何错误,但对齐方式没有改变。我搜索了很多,但唯一的方法似乎是我正在使用的方法。有什么办法可以改变对齐方式吗?任何帮助,将不胜感激。 TIA

来自 DT 文档的 helper functions 部分:

You can pass arbitrary CSS properties to formatStyle()

有关其他信息,请参阅 ?formatStyle

library(DT)

datatable(diamonds[1:10,1:3]) %>%
  formatStyle('cut', `text-align` = 'center')