Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename columns in Shiny dashboard datatable

I have a datatable in my Shiny app. By default, the column names are the column names of the data set. I want to change the column names of the display, without touching the data set itself.

I found this documentation which is exactly what I need, but I'm not sure how to convert this to R syntax.

This is the current way I render the table:

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'))
)

I've tried adding the columnDefs option in several ways but nothing worked.

Any hint would be greatly appreciated!

like image 516
KeshetE Avatar asked Dec 24 '22 10:12

KeshetE


1 Answers

You can use colnames in the renderDataTable. Something like:

  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')})  
like image 96
user2109247 Avatar answered Jan 09 '23 04:01

user2109247