在DT数据表中更改颜色和列标题的名称时出现问题

时间:2019-11-29 17:59:02

标签: html r dt

下面有一个闪亮的仪表板,其中在处理完数据后创建了一个数据表。我想将第一列的颜色更改为红色,但仍保持黑色。我想念什么?它与我的数据帧有关吗?此外,列名也无法更改。

## app.R ##
library(shiny)
library(shinydashboard)
library(visNetwork)
library(geomnet)
library(igraph)
library(dplyr)
library(intergraph)
library(statnet)
library(data.table)
library(DT)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    dataTableOutput("dt")
  )
)

server <- function(input, output) { 

  nodes <- as.data.frame(lesmis[2])
  colnames(nodes) <- c("id", "label")

  #id has to be the same like from and to columns in edges
  nodes$id <- nodes$label

  #Edges
  edges <- as.data.frame(lesmis[1])
  colnames(edges) <- c("from", "to", "width")

  #Create graph for Louvain
  graph <- graph_from_data_frame(edges, directed = FALSE)

  graph <- simplify(graph)
  net <- asNetwork(graph)  # Convert igraph network into an sna object

  br<-data.frame(brokerage(net, cl=get.vertex.attribute(net, "party"))$raw.nli)
  br<-setDT(data.frame(br), keep.rownames = TRUE)[]
  colnames(br)<-c("df","fg","vb",'gh',"v","rt","f")

  output$dt<-renderDataTable({
    colnames(br)[c(1,2,3,4,5,6,7)] <- paste0('<span style="color:',c("red","black","black","black","black","black","black"),'">',colnames(br)[c(1,2,3,4,5,6,7)],'</span>')
    datatable(data.frame(br),rownames = F,escape = F)%>%
      formatStyle(columns = 1, color = "black")%>%
      formatStyle(columns = 2, color = "black")%>%
      formatStyle(columns=  3, color = "black") %>%
      formatStyle(columns = 4, color = "black") %>%
      formatStyle(columns = 5, color = "black")  %>%
      formatStyle(columns = 6, color = "black") %>%
      formatStyle(columns = 7, color = "black") 
  })

  }

shinyApp(ui, server)

0 个答案:

没有答案