kcuilla / reactablefmtr

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

icon_assign fails with error when data is all zero values #25

Closed ChrisWoodsSays closed 2 years ago

ChrisWoodsSays commented 2 years ago

I have a reactable with nested values. In some of the nested data, the values to be represented by icons using icon_assign are all zero.

When this is the case, it fails with the error

Error in seq.default(1, max_value, by = seq_by) : wrong sign in 'by' argument

The code below shows this (I haven't included the nesting as this isn't actually the problem). See https://stackoverflow.com/questions/71428577/incorrect-no-of-icons-assigned-in-reactablefmtr-icon-assign

library(reactable)
library(reactablefmtr)
areas <- data.frame(name = c("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"))
areas$responseCount <- 0 #round(runif(nrow(areas), min = 0, max = 1) * 4)

reactable(
  areas,
  columns = list(
    responseCount = colDef(name = "Responses",
                           cell = icon_assign(areas, #buckets = 4, 
                                              show_values = "left")
    )
  )
)
kcuilla commented 2 years ago

Hi Chris,

I just pushed an update to dev that should fix this. Here are the two examples you provided that appear to be working correctly now:

# zero value example
library(reactablefmtr)
areas <- data.frame(name = c("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"))
areas$responseCount <- 0 

reactable(
  areas,
  columns = list(
    responseCount = colDef(name = "Responses",
                           cell = icon_assign(areas,  
                                              show_values = "left")
    )
  )
)

image

# stackoverflow example
library(reactablefmtr)
areas <- data.frame(name = c("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"))
areas$responseCount <- round(runif(nrow(areas), min = 0, max = 1) * 4)

reactable(
  areas,
  columns = list(
    responseCount = colDef(name = "Responses",
                           cell = icon_assign(areas,  
                                              show_values = "left")
    )
  )
)

image

ChrisWoodsSays commented 2 years ago

Brilliant, thank you Kyle, that works perfectly. Thanks for the speedy response.