formattable icon indicating copy to clipboard operation
formattable copied to clipboard

the color_bar direction

Open WLswert opened this issue 9 years ago • 3 comments

Hi I want to change the color_bar's direction attr . and i set it like this: `color="red" fl=formatter("span", style = function(x) style( display = "inline-block", direction = "ltr", "border-radius" = "4px", "padding-right" = "2px", "background-color" = csscolor(color), width = percent(proportion(as.numeric(x))) ))

formattable(mtcars, list(disp = fl))`

but i don't work . I find the table td style is text-align:right,when i set the text-align:left, the color_bar direction is working. if i want change the color_bar direction,what should I do ?

WLswert avatar Aug 09 '16 07:08 WLswert

Picking up on this - I'd also like a solution if possible. Perhaps an extra argument to call into color_bar()?

ghost avatar Sep 19 '17 21:09 ghost

+1 I'd also be interested in having the option to have the bars going from left to right.

herndonj avatar Jan 18 '18 15:01 herndonj

Here's a fairly simple solution. Use this instead of formattable::color_bar.

my_color_bar <- function(color, fun, ...) {
        fun <- match.fun(fun)
        formatter("span",
                  style = function(x) style(
                    display = "block",
                    direction = "ltr",
                    "border-radius" = "4px",
                    "padding-right" = "4px",
                    "background-color" = csscolor(color),
                    "padding-right" = "2px",
                    "background-color" = csscolor(color),
                    width = percent(fun(x, ...))
                  ))
      }

rio-sanjuan avatar Jan 10 '20 19:01 rio-sanjuan