【问题标题】:Highlighting only one column in a table in Shiny在 Shiny 中仅突出显示表格中的一列
【发布时间】:2014-12-03 03:29:55
【问题描述】:

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

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

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")

})

任何帮助将不胜感激。

谢谢!

【问题讨论】:

    标签: shiny


    【解决方案1】:

    您可以使用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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-11
      • 2016-08-07
      • 2022-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多