我从这篇文章中了解到,我们应该定义一个alignRight
的CSS类,并将其设置为所需的对齐方式:
# ui.R
sidebarLayout(...,
mainPanel(
tags$head(
tags$style(".alignRight { align: right; }", media = "all", type = "text/css")
),
... # content with call to dataTableOutput("myTable")
)
)
然后,在创建 DataTable 时,使用 aoColumnDefs
选项将所需列的类设置为 alignRight
:
# server.R
shinyServer(
function(input, output) {...
output$myTable <- renderDataTable(...,
options = list(
aoColumnDefs = '[{"aTargets": [7, 9, 10], "sClass": "alignRight"}]'
)
)
}
)
然而,这对我的DataTable没有影响,所有列仍然左对齐。我认为这只是一个简单的对齐问题,应该可以很容易地解决,但经过多个小时的研究,显然并非如此。如有任何想法,请不吝赐教。
DataTables
默认是否使用thead
,但如果它们使用的话,只需添加一个处理此情况的CSS即可。稍后我会试一下看能否解决这个问题。 - hrbrmstr