简体   繁体   English

无法在R Shiny中设置数据表样式

[英]Not able to style data table in R Shiny

I am trying to style ELISA data (numeric) table as described here and I get the following error for the code 我正在尝试按此处所述设置ELISA数据(数字)表的样式,并且代码出现以下错误

brks <- quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE) 

在此处输入图片说明

I used the following code as described in the web page. 我使用了网页中描述的以下代码。 Can someone please point out to me what am I missing here? 有人可以告诉我我在这里想念什么吗?

df <- matrix(nrow=8, ncol=12)
for (i in 1:8) {
  for (j in 1:12)
    df[i,j] <- format(as.numeric(elisa65[i,j])/as.numeric(elisa74[i,j]),digits = 4)
}

brks <- quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE)
clrs <- round(seq(255, 40, length.out = length(brks) + 1), 0) 
              %>% {paste0("rgb(255,", ., ",", ., ")")}

DT::datatable(df)  %>% formatStyle(names(df), backgroundColor = styleInterval(brks, clrs))

ELISA数据表

I noticed two issues in your code: 我注意到您的代码中存在两个问题:

  1. clrs is a character and you aren't actually evaluating the calls to rgb clrs是一个字符,您实际上并未评估对rgb的调用
  2. df is a matrix and you are treating it like a data.frame in your code above df是一个matrix ,您在上面的代码data.frame其像data.frame一样data.frame

Try this out 试试看

require(dplyr)
require(DT)
df <- matrix(rnorm(8 * 12), nrow=8, ncol=12)

brks <- quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE)
clrs <- sapply(round(seq(255, 40, length.out = length(brks) + 1), 0), 
               function(x) rgb(255, x, x, maxColorValue = 255))

df <- data.frame(df)
datatable(df)  %>% formatStyle(names(df), backgroundColor = styleInterval(brks, clrs))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM