glin / reactable

Interactive data tables for R
https://glin.github.io/reactable
Other
612 stars 79 forks source link

Is it possible to create table with vertical header? <th> as a row #331

Open nabiila-29 opened 11 months ago

nabiila-29 commented 11 months ago

Example:

image

The idea is to create an information like above without any border

glin commented 11 months ago

Hi, I think this is technically possible if you hide the column headers with CSS and mark up a column as row headers (to be effectively the same as <th>). But I wouldn't really recommend it with reactable, as pretty much every feature assumes a column-wise table. There won't be any useful pagination, filtering, sorting, etc. So I'd really recommend creating this manually as an HTML table or using a different package.

To hide column headers and mark up a column as row headers, here's a quick example:

reactable(
  MASS::Cars93[, c("Model", "Manufacturer", "Min.Price")],
  columns = list(
    Model = colDef(rowHeader = TRUE, style = list(fontWeight = "bold"))
  ),
  defaultColDef = colDef(headerStyle = list(display = "none")),
  bordered = TRUE
)