Search code examples
javascriptrshinyshinydashboardshinyjs

How to delete header row in R shiny dataframe being output using renderTable?


enter image description here

How to delete the header row in the table? I'm using renderTable to output the table and setting the colnames to empty strings. colnames(df) <- c("", "")


Solution

  • colnames(df) <- c("","") does not do what you want here. You want colnames = FALSE in your renderTable() call.

    no header row with colnames = FALSE

    Here is a simple example. Note that the result is the same with or without the colnames<- line. I can reproduce your image with colnames = TRUE

    header row present with default colnames argument

    library(shiny)
    ui <- fluidPage(
        flowLayout(
            mainPanel(
               tableOutput("testTable")
            )
        )
    )
    server <- function(input, output) {
        dat <- data.frame(a = c(1,2,3),b = c(4,5,6),c = c(7,8,9))
        colnames(dat) <- c("","","")
        output$testTable <- renderTable(dat, colnames = FALSE, bordered = TRUE)
    }
    shinyApp(ui = ui, server = server)