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

invisible white text when rendering a table in knitr chunk #144

Open
verajosemanuel opened this issue Nov 12, 2020 · 3 comments
Open

invisible white text when rendering a table in knitr chunk #144

verajosemanuel opened this issue Nov 12, 2020 · 3 comments

Comments

@verajosemanuel
Copy link

products <- data.frame(id = 1:5, 
                        price = c(10, 15, 12, 8, 9),
                        rating = c(5, 4, 4, 3, 4),
                        market_share = percent(c(0.1, 0.12, 0.05, 0.03, 0.14)),
                        revenue = accounting(c(55000, 36400, 12000, -25000, 98100)),
                        profit = accounting(c(25300, 11500, -8200, -46000, 65000)))
formattable(products, list(
  price = color_tile("transparent", "lightpink"),
  rating = color_bar("lightgreen"),
  market_share = color_bar("lightblue"),
  revenue = sign_formatter,
  profit = sign_formatter))

Captura

@verajosemanuel verajosemanuel changed the title invisible white text when rendering a table in knitr invisible white text when rendering a table in knitr chunk Nov 12, 2020
@monkeywithacupcake
Copy link
Contributor

What do you want to happen instead? You want black text?

@verajosemanuel
Copy link
Author

Visible text should suffice.

@monkeywithacupcake
Copy link
Contributor

monkeywithacupcake commented Oct 16, 2021

I think you maybe have another setting, like a default to white text?

When I use your code , I get black text knitted.

Screen Shot 2021-10-16 at 11 34 37

However, when I have an issue with color, possibly that needs to be changing with the background, I write a custom function.

Here's an example, stoplight tile...which turns text white with a red background but otherwise has black text.

stoplighttile <- function(cut1 = .1, cut2 = .2, fun = "comma", digits = 0) {
  fun <- match.fun(fun)
  formatter("span", x ~ fun(x, digits = digits),
            style = function(y) style(
              display = "block",
              padding = "0 4px",
              "border-radius" = "4px",
              "color" = ifelse( y >= cut2, csscolor("#FFFDF9"), csscolor("black")),
              "background-color" = ifelse( y < cut1, csscolor("#50D890"),
                                           ifelse( y < cut2, csscolor("#F6DA63"),
                                                   csscolor("#E32249")))
            )
  )
}

with your data,

formattable(products, list(
  price = color_tile("transparent", "lightpink"),
  rating = color_bar("lightgreen"),
  market_share = stoplighttile(cut1 = 0.05, cut2 = 0.1, fun = "percent", digits = 0)
  )
)

The result is:
Screen Shot 2021-10-16 at 11 41 33

NOTE: I used the tile function on the market share column and not on the price column where you were having the issue, but I hope it makes sense.

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