How to nicely rotate a DT datatable so scrolling is vertical

Viewed 238

I have a DT renrered in my shiny app and it has a lot of columns.

 mtcars2 <- cbind(mtcars, mtcars)
 mtcars2 <- cbind(mtcars, mtcars2)

enter image description here

I would like the table to be inverted as in the column names will be the first column and then all records vertical so I don't need to scroll horizontally but vertically.

enter image description here

I still want mpg to be a column, cyl to be a column etc. Just the way the table is displayed is inverted.

It that anyhow feasible in DT?

Thank you

2 Answers

You can rotate with the CSS property transform:

  div(
    style = "transform: rotateZ(-90deg); transform-origin: bottom;",
    DTOutput("yourOutputId")
  )

t is for transpose. Use the t(...) function from base R.

mtcars2 <- cbind(mtcars, mtcars)
mtcars2 <- cbind(mtcars, mtcars2)

mtcars_t <- t(mtcars2)
Related