Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data_bars: text_position = "outside-base" leads to different horizontal alignment of bars #41

Open
RoelVerbelen opened this issue Nov 1, 2022 · 1 comment

Comments

@RoelVerbelen
Copy link

Thanks for making this useful extension package!

For readability, I'm trying to position the text on the left-hand side of the bars using text_position = "outside-base" but it's leading to a misalignment of the bars due differences in the width of the text. Even when using number_fmt = scales::label_percent(trim = FALSE) which produces strings of equal width, I can't align the bars.

library(dplyr)
library(reactablefmtr)

iris %>% 
  group_by(Species) %>%
  summarise(petal_length_low = mean(Petal.Length < 4)) %>% 
  reactable(
    columns = list(
      petal_length_low = colDef(
        cell = data_bars(., 
                         text_position = "outside-base", 
                         number_fmt = scales::label_percent(trim = FALSE))
      )
    )
  )
  
# Text descriptions have equal width
scales::label_percent(trim = FALSE)(c(1, 0.22, 0))
[1] "100%" " 22%" "  0%"

I'm surprised this is happening though, as I'm using the latest version from github (2.1.0) and the source code seems to try and deal with this situation via stringr::str_pad() (see here).

@fegue
Copy link

fegue commented Jun 21, 2024

Yes, I have the same question and can't find an answer (2 years after it was asked).
Weirdly enough, the first example on the Github Page that uses gradient colors (Cars, Price, Price vs Average) does have aligned bars in the column "Price".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants