raivokolde / pheatmap

Pretty heatmaps
225 stars 83 forks source link

pheatmap is rendered in shiny only after the browser window was resized #85

Open ismirsehregal opened 2 years ago

ismirsehregal commented 2 years ago

Coming from here (or here or here) - When a pheatmap plot is embedded in a shiny app it is rendered only after the browser window was resized:

library(shiny)
library(pheatmap)

ui <- fluidPage(
  shiny::plotOutput("plot2", height = 500)
)

server <- function(input, output) {
  output$plot2 <- renderPlot({
    pheatmap(scale(iris[1:4]))
  })
}

shinyApp(ui, server)
d-pellegrino commented 2 years ago

Inside renderPlot, assigning the pheatmap to an object and printing it should solve the issue (i.e. works for me) Also, call dev.off() before launching the app to avoid interferences

output$plot2 <- renderPlot({
    this_map <- pheatmap(scale(iris[1:4]))
    print(this_map)
  })
DagmaraNiedziela commented 2 years ago

Hi, I have the same problem, I tried the print(plot) solution and it does not work. Also, dev.off() does work, but it means that when I interact with the app during the session (change heatmap input data) the heatmap disappears again.

SamGG commented 2 years ago

Exact same issue. Is there a javascript magic code that might trigger the process called when the window is resized?

ChristianRohde commented 1 year ago

I have 2 pheatmaps on the same page build from 2 different omics but in a very similar workflow. one always gets plotted in shiny. The other does not cooperate with shiny and never seemed to show up. Only here I learned that resizing the window and re-rendering helps to show the plot. Great, but how can I make this plot permanent? I can export the other as rds file and plot outside shiny without any problems. Something must be wrong with the plot. How can I troubleshoot the code of the pheatmap object to find the problem? There is no error or warning shown when I generate the plot.

lshunran commented 4 months ago

Same issue. Is there any solution for that?

jdilme commented 1 month ago

Hi guys, I was having the same problem and none of the suggestions worked for me.

What worked for me (I have no clue why) was to assign the results of the pheatmap function to an object and render it.

app.R

library(shiny)
library(pheatmap)

ui <- fluidPage(
  plotOutput("plot2", height = 500)
)

server <- function(input, output) {

  hm <- pheatmap(scale(iris[1:4]))

  output$plot2 <- renderPlot({
    hm 
  })
}
shinyApp(ui, server)

Hopefully it works for some of you or helps for the bug to be solved :)

lshunran commented 1 month ago

Same issue. Is there any solution for that?

In my case, I have tried many ways to solve it, but when I start the app via RStudio, it still has this issue(sometimes worked out, but most of the time not). However, when I start the app via the command line(just run: Rscript app.R) without changing one line of code, it always works perfectly and also works well after deployment. So, I believe there are some issues with RStudio while using pheatmap.