Q:

R Shiny/Shinydashboard: Hiding the last part of a string in a table

I have a data table that contains some very wide columns and I want to add a scrolling-bar to make it more presentable. So far I have found examples using a scrolling-bar for the entire table - but ideally I would like to have a scrolling-bar for EACH column in the table if that is possible. Below there is an illustrating example. In this code I want a scrolling-bar for both "This_is_a_very_long_name_1", "This_is_a_very_long_name_2" etc.
library("shinydashboard")
library("shiny")

body <- dashboardBody(
  fluidPage(
    column(width = 4,
           box(
             title = "Box title", width = NULL, status = "primary",
             div(style = 'overflow-x: scroll', tableOutput('table'))
          )
    )
)
)

ui <- dashboardPage(
  dashboardHeader(title = "Column layout"),
  dashboardSidebar(),
  body
)

server <- function(input, output) {
  test.table <- data.frame(lapply(1:8, function(x) {1:10}))
  names(test.table) <- paste0('This_is_a_very_long_name_', 1:8)

  output$table <- renderTable({
    test.table
  })

}

# Preview the UI in the console
shinyApp(ui = ui, server = server)

I thought about splitting the table into 8 tables, making a scrolling table for each of them and then putting them next to each other, but space was added betweeen them and it did not look that nice. I think it would be preferable to keeping it as one table (but suggestions are very welcome!).
Does anyone whether this is possible - and how to solve it?
Thanks in advance!

A:

I would not recommend scrolling column header, i think it would not be very clear to read it or so. Here is the code which You can use to get the header in 2 lines so the columns are not too wide:
library("shinydashboard")
library("shiny")
library(DT)

test.table <- data.frame(lapply(1:8, function(x) {1:10}))
names(test.table) <- paste0('This_is_a_very_long_name_', 1:8)

body <- dashboardBody(
  fluidPage(
    column(width = 8,
           box(
             title = "Box title", width = NULL, status = "primary",
             div(style = 'overflow-x: scroll', dataTableOutput('table'))
           )
    )
  )
)

ui <- dashboardPage(
  dashboardHeader(title = "Column layout"),
  dashboardSidebar(),
  body
)

server <- function(input, output) {

  output$table <- renderDataTable({
    names(test.table) <-  gsub("_"," ",names(test.table))
    datatable(test.table, options = list(columnDefs = list(list(width = '100px', targets = c(1:8)))))
  })

}

# Preview the UI in the console
shinyApp(ui = ui, server = server)

[UPDATE] --> Column text rendering 
Here is a one solution which can be usefull for You. There is no scrolling, however Your row text displays only first three characters (the number of characters displayed can be changed) and ..., with mouse over the row You get the pop up with whole variable name in this row:
library("shinydashboard")
library("shiny")
library(DT)

x <- c("aaaaaaaaaaaaaa", "bbbbbbbbbbbb", "ccccccccccc")
y <- c("aaaaaaaaaaaaaa", "bbbbbbbbbbbb", "ccccccccccc")
z <- c(1:3)
data <- data.frame(x,y,z)

body <- dashboardBody(
  fluidPage(
    column(width = 4,
           box(
             title = "Box title", width = NULL, status = "primary",
             div(style = 'overflow-x: scroll', dataTableOutput('table'))
           )
    )
  )
)

ui <- dashboardPage(
  dashboardHeader(title = "Column layout"),
  dashboardSidebar(),
  body
)

server <- function(input, output) {

  output$table <- renderDataTable({
    datatable(data, options = list(columnDefs = list(list(
                                            targets = c(1:3),
                                            render = JS(
                                              "function(data, type, row, meta) {",
                                              "return type === 'display' && data.length > 3 ?",
                                              "'<span title=\"' + data + '\">' + data.substr(0, 3) + '...</span>' : data;",
                                              "}")),list(width = '100px', targets = c(1:3)))))
  })

}

# Preview the UI in the console
shinyApp(ui = ui, server = server)

