Daniel Feller Daniel Feller - 1 month ago 8
R Question

R / d3heatmap / shiny - is there a way to change axis colors?

Unfortunately, at this point there is no functionality in d3heatmap to change the color of the axis labels. This limits one's ability to style the plots using a nifty 'css' style, as you can see below:

enter image description here

There must be a way to manipulate the javascript code; see previous stackoverflow.com question for an easy way to find these files on your local machine.

Here is a reproducible example (although my specific problem is within a {shiny} app):

library(d3heatmap)

d3heatmap(x = mtcars,
Colv = NULL,
scale= "column",
key = FALSE,
yaxis_font_size = "0pt",
xaxis_font_size = "10pt")

Answer

Just add this somewhere in your ui.R. Change the color as needed.

    tags$head(tags$style(HTML("
                              svg.xaxis text {
                                fill: #0000ff;
                              }
                              ")))

Complete example

library(shiny)
library(d3heatmap)

ui <- shinyUI(fluidPage(

   titlePanel("Old Faithful Geyser Data"),

   sidebarLayout(
      sidebarPanel(
        tags$head(tags$style(HTML("
                                  svg.xaxis text {
                                    fill: #0000ff;
                                  }
                                  ")))
      ),

      mainPanel(
         d3heatmapOutput("out")
      )
   )
))

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

  output$out <- renderD3heatmap({
    d3heatmap(x = mtcars,
              Colv = NULL,
              scale= "column",
              key = FALSE,
              yaxis_font_size = "0pt",
              xaxis_font_size = "10pt")
  })

})

shinyApp(ui = ui, server = server)
Comments