How to put color in some datatable values?

Hi community

Im want make better this table. Im want put color when the values are 0 and different to 0.


data <- structure(list(`CANTIDAD DE DATOS VACIOS` = c(0L, 0L, 37987L, 
0L, 0L, 0L, 49L, 0L, 37987L, 0L, 24985L, 37987L, 0L, 13378L, 
14368L, 16792L, 37987L, 14946L, 14943L, 22868L, 0L, 10L, 0L, 
5142L, 29553L, 18306L, 0L, 37987L, 37987L, 0L, 34163L, 37987L, 
37987L, 37987L, 37987L, 37987L, 37987L, 37987L, 37987L, 36268L, 
37987L, 37987L, 0L, 0L, 37938L)), class = "data.frame", row.names = c("COD_INTRO", 


data %>%
  datatable(extensions = 'Buttons',
            class = 'cell-border stripe',
            caption = 'crop: datos vacios segun columna.',
            options = list(dom = 'Blfrtip',
                           buttons = c('csv', 'excel'),
                           lengthMenu = list(c(10,25,50,-1),
                            pageLength = 45))


in general you can achieve any effect in DT that is possible via HTML, if you use datatable's escape=FALSE option.

  y= rep(c(0,1),2)
) |> 
  mutate(y=glue('<SPAN STYLE="text-decoration:underline;
                text-decoration-thickness: 5px;">{y}</SPAN>')) |> 
  datatable(extensions = 'Buttons',
            class = 'cell-border stripe',
            escape = FALSE)

sidenote that text-decoration-thickness is one of those very browser dependent properties; if it doesnt look right in rstudio's viewer pane, expand it into your web browser and its more likely to thicken

1 Like

Hi @nirgrahamuk , Im try my data but dont run and Im change y variable.
But just that I want to send this response, Im check the other y in glue (are 3 y).
Im change for others y variables and run well.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.