【问题标题】:Render multiple plots in shiny ui在闪亮的 ui 中渲染多个绘图
【发布时间】:2020-05-13 09:52:46
【问题描述】:

我想制作一个闪亮的应用程序,用户可以在其中选择基因。然后他会看到这些基因的所有图。

选择部分工作正常(我认为)

ui <- fluidPage(
        titlePanel("Test"),

        sidebarPanel(
            selectInput("genes", "Genes:", seurat_genes, multiple = TRUE),
        ),

        mainPanel(
                uiOutput('out1')
        )
)

现在我想将那些选定的基因绘制在侧边栏面板旁边:

server <- function(input, output) {

    output$out1 = renderUI({
        p = FeaturePlot(sc, features=input$genes, cols=c("lightgrey", param$col), combine=FALSE)
        names(p) = input$genes
        for(i in names(p)) {
            p[[i]] = plot.mystyle(p[[i]], title=i)
            renderPlot(
                print(p[[i]])
            )
        }
    })
}

seurat_genes 是来自 Seurat 分析的数据,Seurat 是一个用于单细胞 RNA-seq 数据的库。因此,用户指定他想要查看哪些基因,FeaturePlot 生成这些图。
FeaturePlot 是 Seurat 的一个函数,它“根据‘特征’(即基因表达)在降维图上为单个细胞着色, PC 分数, 检测到的基因数量等)"

我对 R 非常陌生,尤其是 Shiny,因此请随时提出任何改进建议。

【问题讨论】:

  • seurat_genesFeaturePlot 是什么?
  • seurat_genes 是来自 Seurat 分析的数据,Seurat 是一个用于单细胞 RNA-seq 数据的库。 FeaturePlot 是 Seurat 的一个函数,它“根据‘特征’(即基因表达、PC 分数、检测到的基因数量等)为降维图上的单个细胞着色”
  • 请提供所有相关数据以重现问题

标签: r ggplot2 shiny bioinformatics seurat


【解决方案1】:

找到适合我的解决方案:

library(shiny)
library(Seurat)

# This Data is from my Workspace. I have trouble loading it, so its a workaround and is my next Problem.
seurat_genes = sc.markers[["gene"]]

# Define UI for application that draws a histogram
ui <- fluidPage(
        titlePanel("Einzeldarstellungen von Genen"),

        sidebarPanel(
            selectInput("genes", "Gene:", seurat_genes, multiple = TRUE),
        ),

        mainPanel(
            splitLayout(cellWidths = c("50%","50%"),uiOutput('out_umap'), uiOutput('out_ridge'))
        )
)



# Define server logic required to draw a histogram
server <- function(input, output) {

    output$out_umap = renderUI({
        out = list()

        if (length(input$genes)==0){return(NULL)}
        for (i in 1:length(input$genes)){
            out[[i]] <-  plotOutput(outputId = paste0("plot_umap",i))
        }  
        return(out) 
    })
    observe({  
        for (i in 1:length(input$genes)){  
            local({  #because expressions are evaluated at app init
                ii <- i 
                output[[paste0('plot_umap',ii)]] <- renderPlot({ 
                        return(FeaturePlot(sc, features=input$genes[[ii]], cols=c("lightgrey", param$col), combine=FALSE))
                })
            })
        }                                  
    })

    output$out_ridge = renderUI({
        out = list()

        if (length(input$genes)==0){return(NULL)}
        for (i in 1:length(input$genes)){
            out[[i]] <-  plotOutput(outputId = paste0("plot",i))
        }  
        return(out) 
    })
    observe({  
        for (i in 1:length(input$genes)){  
            local({  #because expressions are evaluated at app init
                ii <- i 
                output[[paste0('plot',ii)]] <- renderPlot({ 
                    return(RidgePlot(sc, features=input$genes[[ii]], combine=FALSE))
                })
            })
        }                                  
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 1970-01-01
    • 2018-04-26
    • 2015-01-11
    • 1970-01-01
    • 2019-11-09
    • 2016-08-15
    • 2021-08-09
    • 2016-12-15
    相关资源
    最近更新 更多