在Shiny中只突出显示一列中的一列

问题描述:

我目前正在设计一个输出表格的Shiny应用程序。我想强调特定列中的单元格(例如,使单元格变蓝)。我已经尝试使用shinyBS包中的HighlightRows函数,但这似乎不起作用。在Shiny中只突出显示一列中的一列

这里是我的服务器脚本组成表的一部分:

output$text1 <- renderTable({ 
    tab1 <- as.data.frame(matrix(c(rrround(input$patha,3),PowerF()$tta,input$nxn,rrround(currentInput()$patha,3),rrround(rxyval()$rxy,3),rrround(rxyval()$rxy_p,3),rround(PowerF()$tra,3), 
            rrround(input$pathp,3),PowerF()$ttp,input$nxn,rrround(currentInput()$pathp,3),rrround(rxyval()$rxyp,3),rrround(rxyval()$rxyp_p,3),rround(PowerF()$trp,3)) 
           ,ncol=7, byrow=TRUE)) 

    rownames(tab1) <- c('Actor', 'Partner') 
    colnames(tab1) <- c('Size', 'Power', 'N','Beta','r','partial r','ncp') 
    tab1.align = "r" 

    highlightRows(session, id='tab1', class = "info", column="Power", regex = ".") 
    print(tab1, type="html") 

})

任何帮助将不胜感激。

谢谢!

您可以使用tags$script修改您的数据表。以下是突出显示示例数据表的3列(1),(5)和(9)的示例。我遇到了类似问题的小问题,你可以查看How to change Datatable row background colour based on the condition in a column, Rshiny

rm(list = ls()) 
library(shiny) 
options(digits.secs=3) 

test_table <- cbind(rep(as.character(Sys.time()),10),rep('a',10),rep('b',10),rep('b',10),rep('c',10),rep('c',10),rep('d',10),rep('d',10),rep('e',10),rep('e',10)) 
colnames(test_table) <- c("Time","Test","T3","T4","T5","T6","T7","T8","T9","T10") 

ui =navbarPage(inverse=TRUE,title = "Coloring datatables", 
       tabPanel("Logs",icon = icon("bell"), 
         mainPanel(htmlOutput("logs"))), 
       tabPanel("Extra 2",icon = icon("bell")), 
       tabPanel("Extra 3",icon = icon("bell")), 
       tags$style(type="text/css", "#logs td:nth-child(1) {text-align:center;background-color:red;color: white;text-align:center}"), 
       tags$style(type="text/css", "#logs td:nth-child(5) {text-align:center;background-color:blue;color: white;text-align:center}"), 
       tags$style(type="text/css", "#logs td:nth-child(9) {text-align:center;background-color:green;color: white;text-align:center}") 
) 
server <- (function(input, output, session) { 

    my_test_table <- reactive({ 
    other_data <- rbind(c(as.character(Sys.time()),(sample(c("Pass","Aggr","Bad"))[1]),round(c(rnorm(1),rnorm(1),rnorm(1),rnorm(1),rnorm(1),rnorm(1),rnorm(1),rnorm(1)),2)), 
         (c(as.character(Sys.time()),(sample(c("Pass","Aggr","Bad"))[1]),round(c(rnorm(1),rnorm(1),rnorm(1),rnorm(1),rnorm(1),rnorm(1),rnorm(1),rnorm(1)),2)))) 
    test_table <<- rbind(apply(other_data, 2, rev),test_table) 
    as.data.frame(test_table) 
    }) 
    output$logs <- renderTable({my_test_table()},include.rownames=FALSE) 

}) 

runApp(list(ui = ui, server = server)) 
+0

谢谢你的建议!我会试着再努力一点。 – RobertA 2014-12-04 02:38:32