Open wkumler opened 1 year ago
One more comment - it's not due to the dendrogram rendering either. We get the same result if we disable dendrogram things with Rowv
and Colv = FALSE
:
heatmaply_mat <- matrix(runif(36), nrow = 6)
long_colname <- paste(sample(letters, 46, replace = TRUE), collapse = "")
colnames(heatmaply_mat) <- c(head(letters, 5), long_colname)
hmc <- heatmaply(heatmaply_mat, Rowv = FALSE, Colv = FALSE)
ui <- fluidPage(plotlyOutput("heatmaply_object"))
server <- function(input, output){
output$heatmaply_object <- renderPlotly(hmc)
}
shinyApp(ui, server)
Thanks for the bug report, the details are super useful and very much appreciated. I'll look into this later today but as I'm not a shiny expert I can't guarantee a quick fix
It seems like a plotly issue with (sub)plots that are too large for the given window, which I can replicate with:
heatmaply_mat <- matrix(runif(36), nrow = 6)
long_colname <- paste(sample(letters, 2000, replace = TRUE), collapse = "")
hmc <- plot_ly(z=heatmaply_mat, type = "heatmap",
y=c(head(letters, 6)),
x=c(head(letters, 6)))
sp <- subplot(replicate(20, hmc, simplify = FALSE))
ui <- fluidPage(plotlyOutput("heatmaply_object"))
server <- function(input, output){
output$heatmaply_object <- renderPlotly(sp)
}
shinyApp(ui, server)
Glad it's useful! The example you give above seems to maybe be a separate issue though, one relating to shiny not rendering more than 16 heatmap subplots no matter the size of the window independent of the length of the row/column names.
# Setup for all later plots
library(shiny)
library(plotly)
ui <- fluidPage(plotlyOutput("heatmaply_object"))
server <- function(input, output){
output$heatmaply_object <- renderPlotly(sp)
}
This works as expected, with the heatmaps rendering both in RStudio and in browser:
sp <- subplot(replicate(16, {
plot_ly(z=matrix(runif(36), nrow = 6), type = "heatmap")
}, simplify = FALSE), nrows = 4)
shinyApp(ui, server)
This one (with 20 subplots) fails in the Shiny app even though it renders just fine in the RStudio "Viewer" window
long_colname <- paste(sample(letters, 50, replace = TRUE), collapse = "")
sp <- subplot(replicate(20, {
plot_ly(z=matrix(runif(36), nrow = 6), type = "heatmap")
}, simplify = FALSE), nrows = 4)
shinyApp(ui, server)
This one (16 subplots, long column names) seems to render just fine (although the long column name chaotically runs behind the plots below it):
sp <- subplot(replicate(16, {
long_colname <- paste(sample(letters, 50, replace = TRUE), collapse = "")
plot_ly(z=matrix(runif(36), nrow = 6), type = "heatmap",
x=c(head(letters, 5), long_colname),
y=c(head(letters, 6)))
}, simplify = FALSE), nrows = 4)
shinyApp(ui, server)
as does this one with long row names:
sp <- subplot(replicate(16, {
long_rowname <- paste(sample(letters, 50, replace = TRUE), collapse = "")
plot_ly(z=matrix(runif(36), nrow = 6), type = "heatmap",
y=c(long_rowname, head(letters, 5)),
x=c(head(letters, 6)))
}, simplify = FALSE), nrows = 4)
shinyApp(ui, server)
Does heatmaply
use a bunch of small subplots in rendering the heatmap, maybe an additional one if the name is detected to be too long somehow?
Seems like a ggplotly thing, which is likely to make it a nightmare to debug. eg this works fine for me:
library(heatmaply)
library(shiny)
library(plotly)
heatmaply_mat <- matrix(runif(36), nrow = 6)
long_colname <- paste(sample(letters, 50, replace = TRUE), collapse = "")
colnames(heatmaply_mat) <- c(head(letters, 5), long_colname)
hmc <- heatmaply(heatmaply_mat, plot_method="plotly")
ui <- fluidPage(
plotlyOutput("heatmaply_object")
)
server <- function(input, output){
output$heatmaply_object <- renderPlotly(hmc)
}
shinyApp(ui, server)
Oof, yep. Can confirm it works fine for me under plot_method="plotly"
but fails under plot_method="ggplot"
. Good to know that I can just switch to the plotly
option if necessary though, thank you!
Hi, super neat package you've got here and one I've found invaluable for data exploration and visualization. I ran into a super strange bug by trying to embed a heatmaply object into a Shiny app, but found that if the column names of the provided matrix were too long then the heatmap wouldn't render at all.
Here's an MWE of the problem:
The character limit seems to be set to 45 - rownames of length 45 render fine, but length 46 fail.
It seems to only affect column names - row names can exceed the 45 character limit and not cause problems
This does seem like a particularly weird heatmaply x shiny problem, as plotly alone can handle long column & row names:
I'm not really familiar enough with the source code to go digging for a solution and it's not critical because I can just abbreviate the row names, but wanted to make sure this was documented for anyone else running into this bizarre problem.