Change table column width output

Hello!

I've been using the formattable package to further configure table outputs on a R Notebook, helping audiences on better understanding the data.

To improve reading of the information I need to give more context on the column names which often times means bigger headers, would it be possible to eithher define a column width or to wrap the column headers do they don't take too much space?

Here is a reproductible example, I'd like to be able to wrap the last two columns if possible:

library(tidyverse)
library(formattable)

d <- diamonds %>%
  group_by(cut) %>%
  summarise(mean_diamond_price = mean(price, na.rm = T),
            mean_diamond_depth = mean(depth, na.rm = T),
            mean_diamond_carat = mean(carat, na.rm = T),
            mean_width_diamond_widest_point = mean(table, na.rm = T))

formattable(d, list(
  mean_diamond_price = color_tile("transparent", "pink"),
  mean_diamond_depth = color_tile("transparent", "pink"),
  mean_diamond_carat = color_tile("transparent", "pink"),
  mean_width_diamond_widest_point = color_tile("transparent", "pink")
))

If anyone gets to this topic in the future, the way I've figured to best apply this changes is to basically rename the columns using html syntax for the line breaks
where you want them

ie. mean_width_diamond_widest_point can become "mean_width
diamond
widest_point"

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.