【发布时间】:2019-08-20 14:42:56
【问题描述】:
如果您在 RStudio 中运行以下代码,它会正确显示两个绘图,但如果您进行小改动(详情如下),它将不再显示第二个绘图。
(请注意,examplePathways 和 exampleRanks 由 fgsea 包提供,因此以下代码应该可以按原样运行。)
library(fgsea)
library(dplyr)
library(ggplot2)
library(shiny)
ui <- fluidPage(
plotOutput("gseaPlot"),
plotOutput("gseaEnrichment")
)
runAnalysis <- function() {
gseaResult <- fgsea(pathways = examplePathways, stats = exampleRanks, nperm = 10)
topPathways <- gseaResult[NES > 0][head(order(desc(NES)), n = 10), pathway]
topPathwayUp <- topPathways[[1]]
gseaEnrichment <- plotEnrichment(examplePathways[[topPathwayUp]], exampleRanks)
gseaPlot <- plotGseaTable(examplePathways[topPathways], exampleRanks, gseaResult)
list(gseaEnrichment = gseaEnrichment, gseaPlot = gseaPlot)
}
server <- function(input, output, session) {
theAnalysis <- runAnalysis()
output$gseaEnrichment <- renderPlot({
theAnalysis$gseaEnrichment
})
output$gseaPlot <- renderPlot({
runAnalysis()$gseaPlot
})
}
shinyApp(ui = ui, server = server)
小变化是,如果我将第二个渲染图更改为使用theAnalysis 而不是runAnalysis(),如下所示:
server <- function(input, output, session) {
theAnalysis <- runAnalysis()
output$gseaEnrichment <- renderPlot({
theAnalysis$gseaEnrichment
})
output$gseaPlot <- renderPlot({
theAnalysis$gseaPlot
})
}
然后第二个图突然出现在 RStudio 查看器窗口中,而不是在浏览器中。
这里发生了什么导致这种行为,我如何在不诉诸运行 runAnalysis() 两次的情况下解决它?
更新:实际上,以下显示的问题更简单,不涉及 Shiny。如果我运行以下代码,该图会显示在 RStudio 绘图查看器中,即使它已存储到变量中(但 plotEnrichment 并非如此):
library(dplyr)
library(fgsea)
library(ggplot2)
gseaResult <- fgsea(pathways = examplePathways, stats = exampleRanks, nperm = 10)
topPathways <- gseaResult[NES > 0][head(order(desc(NES)), n = 10), pathway]
gseaPlot <- plotGseaTable(examplePathways[topPathways], exampleRanks, gseaResult)
更新:显然 fgsea 1.6 版不会发生这种情况(我使用的是 1.8 版),所以它可能是 fgsea 中的一个错误,所以我提交了一个 fgsea 问题。但如果有人能看到问题或有解决方法,我欢迎回答。
【问题讨论】: