circular heatmap in R Shiny
1
0
Entering edit mode
8 months ago
logbio ▴ 30

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 • 703 views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode
8 months ago

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)
ADD COMMENT

Login before adding your answer.

Traffic: 2185 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6