Alejandro Lee
Alejandro Lee

Reputation: 167

Remove header in data table after using transpose

I'm trying to remove a "V1" header in my data table in Shiny.

#Transpose DT
campaign_summary <- t(campaign_summary)

datatable(campaign_summary,
          colnames = NULL,
          options = list(dom = 't', bSort=FALSE),
          class = 'cell-border stripe')

This results in "No matching records found".

How can I remove headers when using renderDataTable to display a data table in Shiny?

Here is the original out of campaign_summary:

      Client Name   Min Date   Max Date Top Funnel Mid Funnel Misc Funnel Bot Funnel     Revenue
1      ABC        2016-05-02 2017-12-04      1,957        72  2         0        550          $0

Here is the output of campaign_summary after using the transpose function:

      [,1]          
Client Name "ABC"
Min Date    "2016-05-02"  
Max Date    "2017-12-04"  
Metric1     "1,957"       
Metric2     "722"         
Metric3     "0"           
Metric4     "550"         
Revenue     "$0"        

Current packages:

  library(rstudioapi)
  library(lubridate)
  library(dplyr)
  library(RPostgreSQL)
  library(DBI)
  library(shiny)
  library(shinydashboard)
  library(scales)
  library(DT)

Upvotes: 1

Views: 1056

Answers (1)

GyD
GyD

Reputation: 4072

Not sure why colnames = NULL is not working, but you can use colnames = "" instead. It doesn't matter since you're disabling sorting anyways.

library(DT)
library(tibble)

df <- tibble(
  `Client Name` = "ABC",
  `Min Date` = "2016-05-02",
  `Max Date` = "2017-12-04"  
)

t_df <- t(df)

DT::datatable(
  t_df, colnames = "", options = list(dom = "t", bSort = FALSE),
  class = "cell-border stripe"
)

Result

Upvotes: 4

Related Questions