admin管理员组

文章数量:1327945

In R shiny and datatable (DT) would like to change the colour of the control text to blue, as it suggests it can be here:

by adjusting the Control text: value to #0000ff which seems to change the colour of the text for the pagination buttons to be blue as well as the search text etc on the webpage, but i would like this for a shiny app with a datatable that has been rendered. Any help would be much appreciated.

Please see below for the example where the text has not had its text colour changed to blue...

  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="pact",
          tags$thead(tags$tr(lapply(colnames(iris), tags$th)))
        )
      ) %>% formatStyle(columns=colnames(iris),color='white',background = 'black',target = 'row')
    )
  })


  shinyApp(ui=ui,server=server)

In R shiny and datatable (DT) would like to change the colour of the control text to blue, as it suggests it can be here:

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

by adjusting the Control text: value to #0000ff which seems to change the colour of the text for the pagination buttons to be blue as well as the search text etc on the webpage, but i would like this for a shiny app with a datatable that has been rendered. Any help would be much appreciated.

Please see below for the example where the text has not had its text colour changed to blue...

  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="pact",
          tags$thead(tags$tr(lapply(colnames(iris), tags$th)))
        )
      ) %>% formatStyle(columns=colnames(iris),color='white',background = 'black',target = 'row')
    )
  })


  shinyApp(ui=ui,server=server)
Share Improve this question edited Nov 19, 2024 at 20:56 Jan 9,5136 gold badges20 silver badges33 bronze badges asked May 25, 2016 at 17:47 h.l.mh.l.m 13.5k22 gold badges90 silver badges173 bronze badges 2
  • You just need to apply some CSS. If you inspect the page you linked, it changes the following elements .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing, .dataTables_wrapper .dataTables_paginate – Xiongbing Jin Commented May 25, 2016 at 18:31
  • 1 can you show me an example? – h.l.m Commented May 25, 2016 at 19:43
Add a ment  | 

1 Answer 1

Reset to default 8

Here is an example (only included UI code)

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

本文标签: javascriptchange colour of controls in R DT datatableStack Overflow