3

I'm creating a shiny app using a dark theme (slate in shinythemes). But when I apply that theme, there are two issues with my renderDataTable output:

  1. The app background is too dark to see the elements outside the table (Showing XX entries, page numbers at the bottom, etc.)
  2. The text in the table is too light to read well.

For issue #2, I've tried options within the renderDataTable arena, like formatStyle(), as well as css options like list(tags$head(tags$style("shipment.table span {color: #333333 ; background: #999999;}"))) but I'm not having any luck with them. I'm new to shiny, DT, and css, which may have something to do with it... Examples of what I've tried are commented out in the code below.

For issue #1, I'm totally stuck. I don't know what those external-to-the-table elements are called, so I'm not having any luck finding things to try!

library(shiny)
library(shinythemes)
library(DT)

d=as.data.frame(cbind(1:100,201:300))

ui<-fluidPage(
    theme = shinytheme("slate"),

    mainPanel(
        DT::dataTableOutput('shipment.table')
        #list(tags$head(tags$style("shipment.table span {color: #333333 ; background: #999999;}")))   
        #tags$head(tags$style("#shipment.table table {color: red;}"))
  )  
)


server<-function(input, output,session) {

output$shipment.table <- renderDataTable(d,filter = 'bottom',
       options = list(lengthMenu = list(c(10,20,50,100,-1), c('10','20','50','100','All')),
       pageLength = 10,autoWidth = TRUE),rownames=F) #%>% formatStyle(1,color="black")
}


shinyApp(ui=ui,server=server)

If you run the app, you'll see a dropdown box with '10' in the top left, but there should be text before and after the box so it says 'Showing 10 entries'. There's also a 1 in the bottom right, but there should be several other pages visible (they are, just in dark text on a dark background). Similarly, the table text is light grey on a lighter grey/white background, which is hard to read. Thanks for any help!

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
kto
  • 135
  • 1
  • 6

2 Answers2

5

amrrs has an excellent answer but it still did not address your other question of changing the colors of the page numbers.. you can do this with adding

library(shiny)
library(shinythemes)
library(DT)

d=as.data.frame(cbind(1:100,201:300))

ui<-fluidPage(
  theme = shinytheme("slate"),



  mainPanel(

    ### add your style inline css values here

    ### added a line of code here too `.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover `###
    tags$style(HTML("
                    .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing, .dataTables_wrapper .dataTables_paginate, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
                    color: #ffffff;
                    }
### ADD THIS HERE ###
                    .dataTables_wrapper .dataTables_paginate .paginate_button{box-sizing:border-box;display:inline-block;min-width:1.5em;padding:0.5em 1em;margin-left:2px;text-align:center;text-decoration:none !important;cursor:pointer;*cursor:hand;color:#ffffff !important;border:1px solid transparent;border-radius:2px}

###To change text and background color of the `Select` box ###
                    .dataTables_length select {
                           color: #0E334A;
                           background-color: #0E334A
                           }

###To change text and background color of the `Search` box ###
                    .dataTables_filter input {
                            color: #0E334A;
                            background-color: #0E334A
                           }

                    thead {
                    color: #ffffff;
                    }

                     tbody {
                    color: #000000;
                    }

                   "


                    ))
  ),
    DT::dataTableOutput('shipment.table')
    #list(tags$head(tags$style("shipment.table span {color: #333333 ; background: #999999;}")))   
    #tags$head(tags$style("#shipment.table table {color: red;}"))
  )  



server<-function(input, output,session) {

  output$shipment.table <- renderDataTable(d,filter = 'bottom',
                                           options = list(lengthMenu = list(c(10,20,50,100,-1), c('10','20','50','100','All')),
                                                          pageLength = 10,autoWidth = TRUE),rownames=F) #%>% formatStyle(1,color="black")
}


shinyApp(ui=ui,server=server)
misheekoh
  • 450
  • 3
  • 17
  • Thank you! That fixes the page numbers. Do you know how to change the text in the dropdown box in the top left (Showing XX entries) to black? It's currently white on white. – kto Feb 14 '19 at 18:19
  • I added some code in the solution above. I also showed you the option to change the background color of the `Select` and `Search` box too. Hope you find this useful – misheekoh Feb 14 '19 at 19:28
  • 1
    Very much, thank you! Accepting this answer for its completeness and instructive aspects. – kto Feb 15 '19 at 19:27
  • Is there a way to do this specifically for each data table on a page? misheeko's answer changes every table, even if it isn't specified until part way down the page before a specific table. – jzadra Feb 18 '22 at 19:45
0

You can add inline css in the code to control this behaviour.

library(shiny)
library(shinythemes)
library(DT)

d=as.data.frame(cbind(1:100,201:300))

ui<-fluidPage(
  theme = shinytheme("slate"),



  mainPanel(

    ### add your style inline css values here

    tags$style(HTML("
                    .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing, .dataTables_wrapper .dataTables_paginate {
                    color: #ffffff;
                    }

                    thead {
                    color: #ffffff;
                    }

                     tbody {
                    color: #000000;
                    }

                   "


                    ))
  ),
    DT::dataTableOutput('shipment.table')
    #list(tags$head(tags$style("shipment.table span {color: #333333 ; background: #999999;}")))   
    #tags$head(tags$style("#shipment.table table {color: red;}"))
  )  



server<-function(input, output,session) {

  output$shipment.table <- renderDataTable(d,filter = 'bottom',
                                           options = list(lengthMenu = list(c(10,20,50,100,-1), c('10','20','50','100','All')),
                                                          pageLength = 10,autoWidth = TRUE),rownames=F) #%>% formatStyle(1,color="black")
}


shinyApp(ui=ui,server=server)

enter image description here

amrrs
  • 6,215
  • 2
  • 18
  • 27
  • 1
    Awesome, thank you! Three hopefully easy fix remaining issues: 1) In the bottom right, you still can't see the page numbers or "Next". Can we make the text for those white as well? I tried tfoot but that didn't do it. 2) When I select the dropdown, the text is now white on a white background. Can we change that text to black? 3) The text in the sliders at the bottom appears to also be white on white. Can that be changed to black as well? I know it doesn't matter here since you can see the numbers above, but my real app will have text in some of those fields that people will need to see. – kto Jan 23 '19 at 17:39