簡體   English   中英

遇到R發光錯誤:非數字矩陣范圍

[英]Encountered R shiny error: non-numeric matrix extent

我寫了一個Rshiny應用程序。 在這里,用戶輸入基因列表,然后該應用程序根據它創建一個生物網絡。 輸入示例如下所示。 該代碼可以作為R腳本在Shinyapp中使用。 輸入是文本而不是數字。

這里對SO進行類似的研究但沒什么用,我的輸入是文本。

任何幫助是極大的贊賞。

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

如果將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 <- string_db$map(subset_dataset(), "genes",removeUnmappedRows = TRUE)mapped_genes <- string_db$map(subset_dataset(), "genes",removeUnmappedRows = TRUE)

輸出:

產量

獎勵:我將req(subset_dataset())添加到renderPlot的第一行,以避免在數據為null時呈現

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM