【问题标题】:Encountered R shiny error: non-numeric matrix extent遇到 R 闪亮错误:非数字矩阵范围
【发布时间】:2019-07-18 20:12:23
【问题描述】:

我写了一个 Rshiny 应用程序。在这里,用户输入一个基因列表,应用程序会从中创建一个生物网络。示例输入如下所示。该代码在shinyapp 中作为R 脚本运行。输入是文本而不是数字。

在 SO here 上研究了类似的问题,但没有多大用处,我的输入是文本。

非常感谢任何帮助。

library(shiny)
library(shinydashboard)
library(STRINGdb)

sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Analysis", tabName = "analysis")
))

body <- dashboardBody(
tabItems(
# Text Area Input for gene list
tabItem(tabName = "analysis", 
        fluidRow(
          box(
            title = "Input gene list here", status = "warning", width 
            = 6, textAreaInput("title1","",value = "", width = 
            '100%',rows=5),
            actionButton("submit", "Submit")
          )
        ),
        fluidRow(
          box(
            title = "Stirng DB network", status = "warning", width = 8, plotOutput("stringplot")
          )
        )
)))

# User interface --
ui <- dashboardPage(
dashboardHeader(title = "Analysis", titleWidth = 300),
sidebar,
body
)

# Server logic
server <- function(input, output) {
subset_dataset <- eventReactive(input$submit, 
{data.frame(strsplit(input$title1,split='[\r\n]'),col.names='genes')})
output$stringplot <- renderPlot({
string_db <- STRINGdb$new()
mapped_genes <- string_db$map(subset_dataset,subset_dataset()$genes,removeUnmappedRows = TRUE)
hits_2<-mapped_genes$STRING_id
string_db$plot_network(hits_2)})
}

shinyApp(ui = ui, server = server)

示例输入为:

BRAF
NF1
NRAS
ERBB3
FLT3
PIK3CA
PTEN
TP53
CTNNB1
APC
SMAD4
NCOR1

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    如果您将browser() 插入您的eventReactive,您可以检查您的data.frame 是否如下所示:

    # c..BRAF....NF1....NRAS....ERBB3....FLT3....PIK3CA....PTEN....TP53... col.names
    # 1                                                                  BRAF     genes
    # 2                                                                   NF1     genes
    # 3                                                                  NRAS     genes
    # ...
    

    您可以改用以下表达式来解决此问题:data.frame(genes = unlist(strsplit(input$title1,split='[\r\n]')))

    结果data.frame

    # genes
    # 1    BRAF
    # 2     NF1
    # 3    NRAS
    # ...
    

    我不熟悉这个包,但在我看来传递给string_db$map 的参数不正确:

    • 第一个参数:data.frame。在 Shiny 中传递 reactiveeventReactive 时,应包含括号(例如:subset_dataset()
    • 第二个参数:使用字符串:(例如:"genes"

    这对我有用: mapped_genes &lt;- string_db$map(subset_dataset(), "genes",removeUnmappedRows = TRUE)

    输出:

    奖励:我会在renderPlot 的第一行添加req(subset_dataset()) 以避免在数据为null 时呈现

    【讨论】:

      猜你喜欢
      • 2015-10-09
      • 2018-02-18
      • 2016-12-11
      • 2020-07-16
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      • 2021-03-24
      相关资源
      最近更新 更多