kcuilla / reactablefmtr

Streamlined Table Styling and Formatting for Reactable
https://kcuilla.github.io/reactablefmtr/
Other
208 stars 27 forks source link

Manually setting colour scale ranges #33

Closed heerymichael closed 2 years ago

heerymichael commented 2 years ago

Hi - I was hoping it would be possible to get some help with applying the cooler fills to cells based on cell value.

I have been working at this but so far haven't been able to find out how to control the end ranges of the fill colours. For example if I wanted my colours to go from white to black (#ffffff to #333333) on a 0 to 100 scale but where the data only ranges from 20 to 80. So I don't want the lowest value within my data to be white - rather want it to be coloured within a scale of 0-100?

Is it possible to control the ranges in this way?

Thanks

Michael

kcuilla commented 2 years ago

Hi Michael,

I just added min_value and max_value to color_tiles() and color_scales() to dev that will allow this. Here is the example you described:

Default:

library(reactablefmtr)

data <- data.frame(
  Group = c("Group 1","Group 2","Group 3","Group 4","Group 5","Group 6","Group 7"),
  Values = c(20, 30, 40, 50, 60, 70, 80)
)

reactable(data,
          pagination = FALSE,
 columns = list(
 Values = colDef(
   cell = color_tiles(data, 
                      colors = c("#ffffff","#333333")))
 ))

image

Including min_value and max_value:

reactable(data,
          pagination = FALSE,
 columns = list(
 Values = colDef(
   cell = color_tiles(data, 
                      colors = c("#ffffff","#333333"),
                      min_value = 0,
                      max_value = 100))
 ))

image

heerymichael commented 2 years ago

Kyle

This is absolutely brilliant - thank you very much for doing this

Do you have a buy me a coffee/donation type scheme?

Would love you give you some sort of token of appreciation

Michael

Sent from my iPhone

On 20 Jun 2022, at 18:59, Kyle Cuilla @.***> wrote:



Hi Michael,

I just added min_value and max_value to color_tiles() and color_scales() to dev that will allow this. Here is the example you described:

Default:

library(reactablefmtr)

data <- data.frame( Group = c("Group 1","Group 2","Group 3","Group 4","Group 5","Group 6","Group 7"), Values = c(20, 30, 40, 50, 60, 70, 80) )

reactable(data, pagination = FALSE, columns = list( Values = colDef( cell = color_tiles(data, colors = c("#ffffff","#333333"))) ))

[image]https://user-images.githubusercontent.com/17436783/174656345-56792359-aef6-4134-99db-230fcbf025c1.png

Including min_value and max_value:

reactable(data, pagination = FALSE, columns = list( Values = colDef( cell = color_tiles(data, colors = c("#ffffff","#333333"), min_value = 0, max_value = 100)) ))

[image]https://user-images.githubusercontent.com/17436783/174656627-205aad35-a2d0-41c0-af87-2705ec510a88.png

— Reply to this email directly, view it on GitHubhttps://github.com/kcuilla/reactablefmtr/issues/33#issuecomment-1160713074, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH4QKM4QF537UNJXNPMFEY3VQCWOPANCNFSM5WHM7HGA. You are receiving this because you authored the thread.Message ID: @.***>

kcuilla commented 2 years ago

No problem! I think it's a really great addition to the package and probably something I should've added sooner!

And thank you so much, I really appreciate that! Here's the link to my coffee page: https://www.buymeacoffee.com/kcuilla