【问题标题】:Change color theme DT table更改颜色主题 DT 表
【发布时间】:2018-10-22 11:16:03
【问题描述】:

我们如何在闪亮的应用程序中更改 DT 表的颜色主题?默认情况下,交替行使用深色和浅灰色。我正在使用formatStyle(target = 'row', backgroundColor = c('yellow', 'red')。但它不起作用,因为它仅适用于列

library(shinydashboard)

header <- dashboardHeader(title = 'title')
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem('dashboard', tabName = 'dashboard', icon = icon('dashboard'))
  )
)
body <- dashboardBody(
           box(
             title = 'box', width = NULL, status = 'primary',
             DT::dataTableOutput('table2')  
  )
)

ui<-dashboardPage(header, sidebar, body)

server = function(input, output) {
  output$table2 = DT::renderDataTable(
    iris, options = list(lengthChange = FALSE)
  )
}

shinyApp(ui, server)

【问题讨论】:

    标签: shiny dt


    【解决方案1】:

    应该这样做,注意我将标题颜色留白:

    library(shinydashboard)
    library(shiny)
    library(DT)
    
    header <- dashboardHeader(title = 'title')
    sidebar <- dashboardSidebar(
      sidebarMenu(
        menuItem('dashboard', tabName = 'dashboard', icon = icon('dashboard'))
      )
    )
    
    body <- dashboardBody(
      tags$style(HTML('table.dataTable tr:nth-child(even) {background-color: pink !important;}')),
      tags$style(HTML('table.dataTable tr:nth-child(odd) {background-color: yellow !important;}')),
      tags$style(HTML('table.dataTable th {background-color: white !important;}')),
      box(
        title = 'box', width = NULL, status = 'primary',
        DT::dataTableOutput('table2')  
      )
    )
    
    ui<-dashboardPage(header, sidebar, body)
    
    server = function(input, output) {
      output$table2 = DT::renderDataTable(
        iris, options = list(lengthChange = FALSE)
      )
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 2016-01-16
      相关资源
      最近更新 更多