0

I'm trying to fill in the background of my table using formattable. Have tried a lot of different things but cant get it working.

The data I'm dealing with is very small:

data frame

running formattable script I get a nice black and white table:

formattable(df[1:2, ],
            align=c("c", "c", "c", "c"))

table using formattable

I'm trying to get row two to have a background colour as dictated by row 3. So for example, the first square of row two would be red, the 2nd red, the 3rd green, and the last in that row would be yellow.

Does anyone have any idea how to do this? I have been trying for hours and can't get anything working.

Thanks

EDIT:

I went with :

formattable(df[1:2, ], 
                            align=c("c", "c", "c", "c"), 
                            list(area(col=1, row=2) ~ 
                                   color_tile(df[3,1], 
                                              df[3,1]), 
                                 area(col=2, row=2) ~ 
                                   color_tile(df[3,2], 
                                              df[3,2]), 
                                 area(col=3, row=2) ~ 
                                   color_tile(df[3,3], 
                                              df[3,3]), 
                                 area(col=4, row=2) ~ 
                                   color_tile(df[3,4], 
                                              df[3,4])))

Maybe thats clunky not sure.. but it worked.

Greg
  • 39
  • 6
  • This [vignette](https://cran.r-project.org/web/packages/formattable/vignettes/formattable-data-frame.html) seems to be a good source of guidance. – nya May 24 '22 at 09:24
  • 1
    Providing a picture of your data is not helpful. It looks like you're fairly new to SO; welcome to the community! If you want great answers quickly, it's best to make your question reproducible. This includes sample data like the output from `dput(dataObject)`. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269). – Kat May 24 '22 at 13:25
  • I thought because the dataframe was so small an image would be fine (someone more clued up than I could turn that into a matrix in a few seconds) Thanks nya right at the end of that page is what I needed. note to self : colour_tile doesn't work but color_tile does – Greg May 25 '22 at 01:25

0 Answers0