rshinydt

Download dataTable is printing HTML along with table


I have this sample app to display and download dataTable. But it is also printing HTML script on top of the downloaded attachment. It is printing logo and title HTML but I also want to preserve them on the app.

library(shiny)
library(DT)
ui <- fluidPage(
  titlePanel(title = tags$div(img(src = "test.jpg", width = 170, height = 115, align = "left"))),
  titlePanel(title = tags$div(class = "header" , tags$p("Cars", tags$br(), tags$h4("MTCARS", style = "text-align: center; color:navy;"), style = "text-align: center; color:navy;"))),
  dataTableOutput("table_output")
)

server <- function(input, output, session){
  output$table_output <- renderDataTable(server=FALSE,{ 
    DT::datatable(head(mtcars), extensions = c('Buttons'), 
                  options = list(autoWidth = FALSE, dom = 'lfrtipB',
                                 buttons = list(list(extend = "csv", text = "CSV", filename = "cars",
                                                     exportOptions = list(modifier = list(page = "all"))),
                                                list(extend = "excel", text = "EXCEL", filename = "cars",
                                                     exportOptions = list(modifier = list(page = "all"))),
                                                list(extend = "pdf", text = "PDF", filename = "cars",
                                                     exportOptions = list(modifier = list(page = "all")))
                                 ))) })
}

shinyApp(ui, server)

Solution

  • I had to change the UI function to get the proper attachment.

    ui <- fluidPage(
      img(src = "test.jpg", width = 170, height = 115, align = "left"),
      tags$div(class = "header" , tags$h2("Cars", tags$br(), tags$h4("MTCARS", style = "text-align: center; color:navy;"), style = "text-align: center; color:navy;")),
      dataTableOutput("table_output")
    )