Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ismirsehregal opened this issue Mar 11, 2022 · 7 comments

Comments

@ismirsehregal
Copy link

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
Copy link

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
Copy link

DagmaraNiedziela commented Jul 7, 2022

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
Copy link

SamGG commented Jul 30, 2022

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

@ChristianRohde
Copy link

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
Copy link

Same issue. Is there any solution for that?

@jdilme
Copy link

jdilme commented Jul 19, 2024

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
Copy link

lshunran commented Jul 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants