【问题标题】:change colour of controls in R DT datatable更改 R DT 数据表中控件的颜色
【发布时间】:2016-09-23 11:33:45
【问题描述】:

在 R 中,闪亮和数据表 (DT) 想将控件文本的颜色更改为蓝色,因为它表明它可以在这里:

https://datatables.net/manual/styling/theme-creator

通过将Control text: 值调整为#0000ff,这似乎将分页按钮的文本颜色以及网页上的搜索文本等更改为蓝色,但我希望这是一个闪亮的应用程序带有已渲染的datatable。任何帮助将不胜感激。

请参阅下面的文本未将其文本颜色更改为蓝色的示例...

  library(DT)
  library(shiny)

  ui=shinyUI(

    fluidPage(
      tags$head(tags$style(HTML("table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
                                background-color: #9c4242 !important;
                                } "))),
      DT::dataTableOutput("tt")
      )
    )

  server=shinyServer(function(input, output) {
    output$tt=DT::renderDataTable(
      DT:::datatable(
        head(iris, 50),rownames = FALSE,options = list(dom='ptl',
                                                       initComplete = JS(
                                                         "function(settings, json) {",
                                                         "$(this.api().table().header()).css({'background-color': '#000', 'color': '#fff'});",
                                                         "}")
        ),
        container = tags$table(
          class="compact",
          tags$thead(tags$tr(lapply(colnames(iris), tags$th)))
        )
      ) %>% formatStyle(columns=colnames(iris),color='white',background = 'black',target = 'row')
    )
  })


  shinyApp(ui=ui,server=server)

【问题讨论】:

  • 你只需要应用一些 CSS。如果您检查您链接的页面,它会更改以下元素.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing, .dataTables_wrapper .dataTables_paginate
  • 你能给我举个例子吗?

标签: javascript r datatable shiny


【解决方案1】:

这是一个示例(仅包含 UI 代码)

ui=shinyUI(

    fluidPage(
        tags$head(tags$style(HTML("table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
                                  background-color: #9c4242 !important;
                                  }
                                  "))),
        tags$style(HTML(".dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing,.dataTables_wrapper .dataTables_paginate .paginate_button, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
            color: #0000ff !important;
        }")),
      DT::dataTableOutput("tt")
        )
    )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-29
    • 2016-11-20
    • 2021-03-17
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 2019-05-08
    • 2020-06-24
    相关资源
    最近更新 更多