This is a test version of Biostars. For the public version, visit https://www.biostars.org.
circular heatmap in R Shiny

I want to see the circular heatmap in the output of my code in R Shiny App. However, when I first run the code, circular heatmap works fine, but no longer outputs circular.

library(shiny)
library(shinydashboard)
library(ComplexHeatmap)
library(BiocManager)
library(circlize)
library(RColorBrewer)



# Shiny app
ui <- dashboardPage(
  dashboardHeader(title = "Circular Heatmap"),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      box(
        title = "Circular Heatmap",
        width = 12,
        solidHeader = TRUE,
        collapsible = TRUE,
        plotOutput("heatmap_plot")
      )
    )
  )
)

server <- function(input, output) {
  output$heatmap_plot <- renderPlot({
    #dataset

    set.seed(123)
    mat <- matrix(rnorm(100), ncol = 10)
    colnames(mat) <- paste0("Gene", 1:10)
    rownames(mat) <- paste0("Sample", 1:10)

    # ComplexHeatmap create
    color_palette <- colorRampPalette(brewer.pal(11, "RdBu"))(101)
    col_fun <- colorRamp2(seq(-3, 3, length.out = 101), color_palette)

    ht <- Heatmap(mat, 
                  col = col_fun, 
                  name = "Expression",
                  show_row_names = FALSE,
                  show_column_names = TRUE,
                  cluster_rows = FALSE,
                  cluster_columns = FALSE)

    # ComplexHeatmap 
    draw(ht)

    # ComplexHeatmap to circular
    circos.par(start.degree = 90)
    circos.heatmap(mat, col = col_fun)  # control.circle argümanını kaldırdık
  })
}

shinyApp(ui, server)
complexheatmap shiny r

Yes please remove Heatmap part of code-

Your final code will be like this-

rm(list=ls())  
library(shiny)
library(circlize)
library(RColorBrewer)

# Shiny app

ui <- dashboardPage(
dashboardHeader(title = "Circular Heatmap"),
dashboardSidebar(),
dashboardBody(
fluidRow(
  box(
    title = "Circular Heatmap",
    width = 12,
    solidHeader = TRUE,
    collapsible = TRUE,
    plotOutput("heatmap_plot")))))

server <- function(input, output) {
 output$heatmap_plot <- renderPlot({
#dataset

set.seed(123)
mat <- matrix(rnorm(100), ncol = 10)
colnames(mat) <- paste0("Gene", 1:10)
rownames(mat) <- paste0("Sample", 1:10)

# ComplexHeatmap create
color_palette <- colorRampPalette(brewer.pal(11, "RdBu"))(101)
col_fun <- colorRamp2(seq(-3, 3, length.out = 101), color_palette)



# Circular Heatmap
circos.clear()
circos.par(start.degree = 90)
circos.heatmap(mat, col = col_fun)})}

shinyApp(ui, server)

And your plot will look like this-

enter image description here

1 answer

This is because you are making and drawing a typical ComplexHeatmap before your circos code. You don't need to do that, since the circos.heatmap function doesn't need the Heatmap output - it just uses the same input matrix.

So just remove:

ht <- Heatmap(mat, 
                  col = col_fun, 
                  name = "Expression",
                  show_row_names = FALSE,
                  show_column_names = TRUE,
                  cluster_rows = FALSE,
                  cluster_columns = FALSE)

# ComplexHeatmap 
draw(ht)

Log in to answer this question.