kableExtra icon indicating copy to clipboard operation
kableExtra copied to clipboard

pre-kable image generation

Open r2evans opened this issue 3 years ago • 1 comments

Consider this code:

library(dplyr)
mtcars %>%
  group_by(cyl) %>%
  summarize(mpg_box = list(spec_boxplot(mpg))) %>%
  ungroup()
# `summarise()` ungrouping output (override with `.groups` argument)
# # A tibble: 3 x 2
#     cyl mpg_box   
#   <dbl> <list>    
# 1     4 <kblExtIP>
# 2     6 <kblExtIP>
# 3     8 <kblExtIP>

It could be very powerful to pre-define the sparklines (or other things) and have kableExtra interpret them specially, such as

mtcars %>%
  group_by(cyl) %>%
  summarize(
    mpg_box = list(spec_boxplot(mpg)),
    mpgdisp_scatter = list(spec_line(mpg, disp))
  ) %>%
  ungroup() %>%
  kbl() %>%
  column_spec(2, image = .) %>%
  column_spec(3, image = identity(.))

where the image = . or perhaps image = identity(.) (just multiple examples, the same intention here) or something unambiguous says to interpret the pre-existing objects in that column as an image. (I don't know kableExtra well enough to know if this is easily extended to other things that column_spec can do.)

This mitigates the need to break things out into a list before=hand and process things ... and provides for a lot of control and flexibility.

Thoughts?

r2evans avatar Aug 31 '20 23:08 r2evans

  column_spec(3, image = TRUE)

to indicate that the third column should be used untouched?

r2evans avatar Sep 01 '20 00:09 r2evans