Search code examples
rshinyggvis

How to change background color of gvisTable in Shiny App (R)


I cannot get the background of the gvisTable in Shiny to be anything other than white. I am trying this, but it does not work:

gvisTable(finalTable, options = list(page='enable', 
                                     width='1400px', height='300px',
                                     backgroundColor="black"))

Solution

  • You can use the cssClassNames options:

    require(shiny)
    require(googleVis)
    runApp(
      list(ui = pageWithSidebar(
        headerPanel("googleVis on Shiny"),
        sidebarPanel(
          selectInput("dataset", "Choose a dataset:",
                      choices = c("rock", "pressure", "cars"))
        ),
        mainPanel(
          htmlOutput("table")
          ,tags$head(tags$style(type="text/css", ".myTableHeadrow {background-color:red;} .myTablerow {background-color:yellow;}"))
        )
      ),
      server =function(input, output)({
        output$table <- renderGvis({
          ## Table with enabled paging
          tbl2 <- gvisTable(Population, options=list(page='enable', height=300, cssClassNames = "{headerRow: 'myTableHeadrow', tableRow: 'myTablerow'}", alternatingRowStyle = FALSE), chartid = "mytable")
          tbl2
        })    
      })
      )
    )
    

    googleVis Example