Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to custom format numeric columns in shiny renderTable?

Tags:

format

r

shiny

I would like to custom format the numeric columns in my table. I would like to have the p-values in scientific format, and the other numeric columns with 0 or 2 decimals. How can I do this? I have tried

output$addtable <- renderTable({ ...} , digits = -2)

but that converts all numeric columns into scientific format.

output$addtable <- renderTable({
    dataset <- datasetInput()
    d=dataset[which(dataset$gene==input$textgene),]
    names(d)=c("Gene","P","CmafUsed","NsnpsUsed","MinP","MinGene","Ratio")
    if(dim(d)[1]==0) {'No entry found'} else return(d)    
  })  

What I am looking for is to have:

Gene    P       CmafUsed    NsnpsUsed   MinP    MinGene Ratio
GENE1   1.50E-05    0.20    12        4.62E-05  GENE2   1.11
like image 346
Bea Avatar asked Feb 06 '26 08:02

Bea


1 Answers

Since you mentioned scientific, this comes to mind:

df = data.frame(P = 1e-6, Rest = 1e-6)
df$P <- format(df$P, scientific = FALSE)
df$Rest <- format(df$Rest, scientific = TRUE)
like image 163
Tonio Liebrand Avatar answered Feb 09 '26 03:02

Tonio Liebrand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!