Consider the example data.frame
df <- data.frame(
id = 1:4,
name = c(\"Bob\", \"Ashley\", \"James\", \"David\"),
age = c(48, NA, 40, 28),
test1_score
Another solution which worked for me was using str_remove_all()
. Because color_bar()
in formattable
produces HTML output as a character, you can just remove the string "NA".
Note that this has the potential to mess up the HTML if you happened to have NA
anywhere else. Also worth noting is that I wrap a percent function around your_var
.
This was the best way I could come up with to convert my numeric to percent and apply color_bar()
. The code is below:
df %>%
# First mutate w/color_bar()
mutate(your_var= color_bar("green", na.rm=T)(percent(your_var, digits = 1))) %>%
# Second mutate
mutate(your_var = str_remove_all(your_var, "NA"))
NA
Also, in case anyone hasn't seen this yet: Awesome tables in HTML - Integration with formattable