D3heatmap and networkD3 not working together

80 views
Skip to first unread message

Ewelina Sowka

unread,
Aug 9, 2017, 1:06:18 PM8/9/17
to Shiny - Web Framework for R
Hello.
When I try to render on one of shiny dashboard pages d3heatmap it is not working with networkD3 possibly rendering on another page. When I comment network heatmap is working. Could you please help me to solve this problem?

Aline Deschamps

unread,
Aug 10, 2017, 10:19:52 AM8/10/17
to Shiny - Web Framework for R
Hello,

I'm not sure without seeing your code but may be it could be something linked to default id for d3heatmap and networkD3 viz ?
If you have two d3heatmap in your app (and no networkD3 or a commented networkD3), is it still working ?

HTH ! :)

Best regards.


-- Aline

Ewelina Sowka

unread,
Aug 23, 2017, 2:43:04 AM8/23/17
to Shiny - Web Framework for R
Hello
It seems not to be working with 2 heatmaps. I would be really greatfull if you could help.
Code for the heatmap and network:

ui.R
tabItem(tabName = "heatMap",
              h2("Heat Map"),
              fluidRow(
                box(
                  width=3,
                  # collapsible = TRUE,
                  conditionalPanel(
                    condition = "input.goButton == true",
                    uiOutput("heatmapOptions1"),
                    conditionalPanel(
                      condition = "input.statisticalCriterion != null",
                      uiOutput("heatmapOptions2"),
                      actionButton("goButtonHeat", "Draw Heatmap"))
                  )),
                box(width=9,
                    uiOutput("pixelation"))
                ))
tabItem(tabName = "network",
        h2("Network Analysis"),
        fluidRow(
          box(width = 12,
              conditionalPanel(
                condition = "input.goData == true",
                actionButton("doNets", "Do Network Analysis")
                # ,
                # downloadButton("downloadSimpleNetwork", "Download Network")
              ))
          ,
          box(width = 12,
              simpleNetworkOutput("networkData", width= "100%", height="500px"))
          )
        )
server.R
# heatmap height
  output$pixelation <- renderUI({
    d3heatmapOutput("heatmap",
                    width = "100%",
                    height = "700px")
    })
  
  # log2 data transformation
  log2_datasetInput <- reactive({
    cpm(slimStats(), prior.count=2, log=TRUE)
  })
  
  output$heatmap <- d3heatmap::renderD3heatmap({
    validate(need(input$goButtonHeat !=0 , "To create a heatmap showing statistically significant genes, first perform differential expression analysis and then specify your parameters and press 'Draw Heatmap' button"))
    if(input$log2_transformed_data){dataset<-log2_datasetInput()}else{dataset<-slimStats()}
    d3heatmap(
        dataset,
        cexRow = as.numeric(as.character(input$xfontsize)),
        cexCol = as.numeric(as.character(input$yfontsize)),
        colors = colorRampPalette(c("red", "yellow", "green"))(n = input$numberOfInterestingGenes),
        k_row = input$color_row_branches,
        k_col = input$color_column_branches,
        dendrogram = input$dendrogram
      )
  })
# simple network engine prep
  grow <- function(nominal_GO_df, rownamespwfOne, enriched.GO, Genome, topEnriched) ({
    total = list()
    getGo <- getgo(rownamespwfOne, Genome, input$geneRef)
    Base = data.table(rownamespwfOne, getGo)
    for(go in nominal_GO_df$ind[1:topEnriched]){
      Names <- Base$rownamespwfOne[grep(go,Base$getGo)]
      nameList = list(Names) 
      total = append(total, nameList)
    }
    names(total) <- nominal_GO_df$ind[1:topEnriched]
    total <- total
  })
  # simple network engine
  network <- reactive({
    enriched.GO <- enriched()
    #network analysis loop (FDR vs nominal p-value) within simple network engine
    if(!length(enriched.GO) == 0){
      nominal_GO_df <- stack(lapply(mget(enriched.GO, GOTERM, ifnotfound = NA), Term)) 
      
      total <- grow(nominal_GO_df, rownamespwfOne, input$chooseEnriched, input$Genome, input$numberGenes)
      namesGo <- names(total)
      vector = c()
      targetVector = c()
      
      for (go in 1:length(namesGo)){
        lengthName <- length(total[[go]])
        for(populate in 1:lengthName){
          nameGene <- nominal_GO_df$values[grep(namesGo[go], nominal_GO_df$ind)]
          vector = append(vector, nameGene)
          targetVector = append(targetVector, total[[go]][populate])
        }
      }
      src <- vector
      target <- targetVector
      networkData <- data.frame(src, target)   
      simpleNetwork(networkData)
                    # , charge = -1000, opacity = 1, zoom = T)
    }
    else {
      return(validate(need(input$goData == 0, "No enriched genes are available to make a network at this statistical cutoff level")))
    }
  })
  
  # simple network output
  output$networkData <- renderSimpleNetwork({
    if (input$doNets == 0) {return(validate(
      need(input$countMatrix != 0, "For network analysis, please first select a file for input") %then%
        need(input$goButton != 0, "For network analysis, please first perform Differential Expression Analysis") %then%
        need(input$goData != 0, "For network analysis, please perform Gene Ontology analysis") %then%
        need(input$doNets != 0, "For network analysis, please click on 'Do Network Analysis' and wait for about 5-30 seconds")
    ))}
    else {
      network()
    }
  })
})

This are just the parts of code but it was too much to copy everything. 
Thank You.

Joe Cheng

unread,
Aug 23, 2017, 5:02:06 PM8/23/17
to Ewelina Sowka, Shiny - Web Framework for R
Any error messages in your browser's JS console?

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/a9ef894a-60db-424e-9142-ef629a0c1d3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ewelina Sowka

unread,
Aug 23, 2017, 7:25:24 PM8/23/17
to Shiny - Web Framework for R, sowkae...@gmail.com
I just have noticed it:
Uncaught TypeError: xaxis.style is not a function
    at eval (eval at <anonymous> (jquery.min.js:2), <anonymous>:194:11)
    at heatmap (eval at <anonymous> (jquery.min.js:2), <anonymous>:214:5)
    at eval (eval at <anonymous> (jquery.min.js:2), <anonymous>:58:16)
    at Image.img.onload (eval at <anonymous> (jquery.min.js:2), <anonymous>:110:7)

Amanda Mason-Singh

unread,
Sep 20, 2017, 2:45:08 PM9/20/17
to Shiny - Web Framework for R
Hello Ewelina!

I am having this same issue when using both the networkD3 package and the d3heatmap package to plot different figures on the same R Shiny app.


It looks like the problem is likely due to d3heatmap using an older version of D3.js, while networkD3 uses (presumably) a never version of D3.js.

I have left a comment on the github page for d3heatmap to see if the issue will be resolved.

If you were able to solve your problem another way, please share.  :)

Best,

Amanda
Reply all
Reply to author
Forward
0 new messages