重命名 Shiny 仪表板数据表中的列

Kes*_*etE 4 jquery r datatables shiny shinydashboard

我的 Shiny 应用中有一个数据表。默认情况下,列名是数据集的列名。我想更改显示的列名,而不触及数据集本身。

我发现这个文档正是我需要的,但我不确定如何将其转换为 R 语法。

这是我呈现表格的当前方式:

output$score_data_table <- renderDataTable({
    selectedArea_overview_TC()}, 
    options = list(orderClasses = TRUE, 
                   lengthMenu = list(c(15,25,50,100,-1), c('15','25','50','100','All')),
                   pageLength = 15,
                   order=list(1, 'desc'))
)
Run Code Online (Sandbox Code Playgroud)

我尝试columnDefs以多种方式添加该选项,但没有任何效果。

任何提示将不胜感激!

小智 6

您可以在 renderDataTable 中使用列名。就像是:

  output$table1 <- DT::renderDataTable({
     datatable(messages(),
     colnames = c('Type', 'Message', 'Check', 'Entity',   'ID','File'), 
     options = list(pageLength = 50, autoWidth = TRUE,
     columnDefs = list(list(width = '800px', targets = c(2)))),filter='top')})  
Run Code Online (Sandbox Code Playgroud)