talgalili / d3heatmap

A D3.js-based heatmap htmlwidget for R
Other
236 stars 93 forks source link

d3heatmap does not render in flexdashboard when scatterD3 also used #77

Open andreamrau opened 8 years ago

andreamrau commented 8 years ago

Hello, I'm currently working on a flexdashboard in which I would like to include both a d3heatmap and a scatterD3. When d3heatmap is used by itself, it renders just fine; however, when both are present the d3heatmap does not render (regardless of whether the chunk is placed first or last). The same problem occurs in rmarkdown. Minimal reproducible example below, thanks! -- Andrea

---
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
runtime: shiny
---

```{r global, include=FALSE}
library(flexdashboard)
library(d3heatmap)
library(scatterD3)
data(mtcars)
```

scatterD3
=====================================
Renders fine.

```{r, scatterD3, eval=FALSE}
scatterD3(data = mtcars, x = wt, y = mpg, 
          point_size = 100, point_opacity = 0.5,
          hover_size = 4, hover_opacity = 1)
```

d3heatmap
===================================== 
Does not render (unless chunk above set to eval=FALSE)!

```{r, d3heatmap}
d3heatmap(mtcars, scale="column", colors="Blues")
```
andreamrau commented 8 years ago

Actually, I see that d3heatmap seems to work just fine in flexdashboard in tandem with plotly and metricsgraphics, so this may be an issue for scatterD3 instead.

ThomasSiegmund commented 7 years ago

This happens because scatterD3 uses D3.js version 4.x,, while d3heatmap uses version 3.x. If both widgets are in the same page, htmlwidgets loads only the latest D3 version, 4.x. This leaves d3heatmap broken. There are two options: either d3heatmap is upgraded to D3 version 4, or scatterD3 uses a custom bundle of D3 in an own namespace.

jcheng5 commented 7 years ago

Shoot. I think d3 v3 and d3 v4 can actually exist side-by-side, but, because they use the same name "d3" htmltools/htmlwidgets assumes that they are substitutes. One fix would be to change the name of the latter to d3v4, but that's something that everyone that bundles d3 v4 would have to standardize on.

Another possibility would be for scatterD3 to "compile in" its copy of d3 v4 using browserify or webpack--it was my understanding that this is how d3 v4 was designed to be used. If that was the case then there would be no separate d3 dependency at all for d3 v4.

amandamasonsingh commented 7 years ago

I have this same issue (i.e., the d3heatmap image will not render - however the title of the heat map does render) when using both the networkD3 and d3heatmap packages in an R Shiny app.

Are there plans to fix this issue (assuming the problem is due to d3heatmap using an older version of D3.js, whereas other packages are using newer/the most recent version of D3.js)?