Formatting dt table by row or cell as percentage

Hi , good day everyone, have some trouble finding any documents to point me in the correct direction.
I´ve been trying to format a dttable but I need to do it just in some cells or rows, as far as I know this can be done but by column. Does anyone know how to achieve this? heres my code to create the table, smo is a function to get the data frame which works correctly, just need the format code.

output$tableDTy=DT::renderDataTable(SMO()[1:nrow(SMO()),],
options=list(paging=T,pageLength = 5),
rownames=F,
filter="top",
selection="single")

thanks a lot

You could use rowCallback seen here or formatStyle seen here

thanks a lot for your help, but in both cases it seems like it is formatting just a column instead of a row, it says row rendering but the result is displaying column.

Ah, well if you don't mind adding another dependency, the formattable package might be what you're looking for based on this document

1 Like

thanks a lot , I think this would work but dont know how to use it with my reactive function. It works as it is right now but not using my reactive function

My function returns the dataframe and it fills up by executing a query

 VarPrecio=reactive({
    validate(
      need(nrow(values$mydata)>0,"")
    )
    sem4=c((values$mydata[origTable_selected(),107]/values$mydata[origTable_selected(),55])/(values$mydata[origTable_selected(),111]/values$mydata[origTable_selected(),46])-1)
    sem3=c((values$mydata[origTable_selected(),108]/values$mydata[origTable_selected(),56])/(values$mydata[origTable_selected(),112]/values$mydata[origTable_selected(),47])-1)
    sem2=c((values$mydata[origTable_selected(),109]/values$mydata[origTable_selected(),57])/(values$mydata[origTable_selected(),113]/values$mydata[origTable_selected(),48])-1)
    sem1=c((values$mydata[origTable_selected(),110]/values$mydata[origTable_selected(),58])/(values$mydata[origTable_selected(),114]/values$mydata[origTable_selected(),49])-1)
    w4=c(((values$mydata[origTable_selected(),107]+values$mydata[origTable_selected(),108]+values$mydata[origTable_selected(),109]+values$mydata[origTable_selected(),110])/
      (values$mydata[origTable_selected(),55]+values$mydata[origTable_selected(),56]+values$mydata[origTable_selected(),57]+values$mydata[origTable_selected(),58]))/ 
        ((values$mydata[origTable_selected(),111]+values$mydata[origTable_selected(),112]+values$mydata[origTable_selected(),113]+values$mydata[origTable_selected(),114])/
        (values$mydata[origTable_selected(),46]+values$mydata[origTable_selected(),47]+values$mydata[origTable_selected(),48]+values$mydata[origTable_selected(),49]))-1)
    text_tbl <- data.frame(sem4,sem3,sem2,sem1,w4)
    row.names(text_tbl)=c("VarPrecio")
    return(text_tbl)  
  })
library(DT)

data <- matrix(c(0,0.64,-0.76234,0.43,1,19),nrow=3,byrow=T)

datatable(data,options=list(
  rowCallback=JS("function( row, data, index ) {
                 $('td:eq(0)', row).html(data[0] % 1 != 0 | data[0]==0 ? (data[0]*100).toFixed(1) +'%':data[0]);
                 $('td:eq(1)', row).html(data[1] % 1 != 0 | data[1]==0 ? (data[1]*100).toFixed(1) +'%':data[1]);
                 }
                 ")))