向 InteractiveComplexHeatmap R shiny app 添加绘图渲染选项

问题描述 投票:0回答:0

我正在尝试扩展 InteractiveComplexHeatmap 的 可点击热图的简单示例。理想情况下,我希望

InteractiveComplexHeatmapOutput
在点击事件生成的输出中包含一个图,但这似乎太复杂了,所以现在我试图包含一个侧面板,允许用户选择一个热图行和列标签,将生成该图。

在下面的示例中,我有一个

gene
x
pair
表达矩阵(
mat
,其中
pair
表示来自处理-对照配对样本的基因的组合表达值),用于生成热图,以及一个
data.frame
(
fc.df
),每个
effect.size
中的每个
effect.size.error
都有一个
gene
pair
值。我想添加的情节是
ggplot2
geom_bar
+
geom_errorbar
显示选定的
gene
pair
相应的
effect.size
effect.size.error
.

这是我的代码:

suppressPackageStartupMessages(library(InteractiveComplexHeatmap))
suppressPackageStartupMessages(library(ComplexHeatmap))
suppressPackageStartupMessages(library(ggplot2))


set.seed(1)
mat <- matrix(rnorm(10000,0,1),nrow = 1000, ncol = 10,dimnames = list(paste0("gene",1:1000),paste0("pair",1:10)))
fc.df <- do.call(rbind,lapply(paste0("pair",1:10), function(p){
   data.frame(gene = paste0("gene",1:1000), pair = p, effect.size = rnorm(1000,0,1), effect.size.error = sd(rnorm(1000,0,0.5)))
}))
ht <- Heatmap(mat,show_row_names=F)
ht <- draw(ht)


server <- function(input, output, session)
{
  makeInteractiveComplexHeatmap(input, output, session, ht, "heatmap")
  
  output$gene <- renderUI({
    selectInput("gene", "Select gene", choices = unique(rownames(mat)), multiple = F)
  })

  output$pair <- renderUI({
    selectInput("pair", "Select pair", choices = unique(colnames(mat)), multiple = F)
  })
  
  output$effectPlot <- reactive({
    req(input$gene, input$pair)
    plot.df <- dplyr::filter(fc.df, gene == input$gene & pair == input$pair)
    bar.plot <- ggplot(plot.df, aes(x = gene, y = effect.size)) + 
      geom_bar(stat = "identity", color = "black", position = position_dodge()) +
      geom_errorbar(aes(ymin = effect.size-effect.size.error, ymax = effect.size+effect.size.error),width = 0.2, position = position_dodge(0.9)) + 
      theme_minimal()+theme(axis.title.x=element_blank(),axis.title.y=element_blank())
    renderPlot(effectPlot)
  })
}

ui <- fluidPage(
  titlePanel("Pairs Effects Explorer",windowTitle="Pairs Effects Explorer"),
  sidebarLayout(
    sidebarPanel(
      tags$head(
        tags$style(HTML(".multicol {-webkit-column-count: 3; /* Chrome, Safari, Opera */-moz-column-count: 3; /* Firefox */column-count: 3;}")),
        tags$style(type="text/css", "#loadmessage {position: fixed;top: 0px;left: 0px;width: 100%;padding: 5px 0px 5px 0px;text-align: center;font-weight: bold;font-size: 100%;color: #000000;background-color: #CCFF66;z-index: 105;}"),
        tags$style(type="text/css",".shiny-output-error { visibility: hidden; }",".shiny-output-error:before { visibility: hidden; }")),
      conditionalPanel(condition="$('html').hasClass('shiny-busy')",tags$div("In Progress...",id="loadmessage")),
      uiOutput("gene"),
      uiOutput("pair"),
    ),
    mainPanel(
      InteractiveComplexHeatmapOutput(heatmap_id="heatmap",title1="Expression Heatmap",title3="Gene-Pair Info",
                                                width1=800,height1=800,width3=400,height3=300,
                                                action="click",response="click",output_ui_float=F),
      plotOutput("effectPlot")
    )
  )
)

shinyApp(ui, server)

问题/问题是:

  1. 它不会呈现
    effectPlot
    - 我如何让它出现?
  2. 我希望呈现的
    effectPlot
    出现在选择列表下方的侧面板中,或者出现在主面板的右侧,专用于子热图的区域下方。
r shiny interactive complexheatmap
© www.soinside.com 2019 - 2024. All rights reserved.