闪亮的渲染UI错误

Ven*_*Yao 2 r render shiny

我使用 编写了一个小型闪亮应用程序renderUI。它运行正确,但R控制台抛出错误消息

if (nchar(locus) == 12) { 中的错误:参数长度为零

每次我运行这个应用程序时。

这是我的脚本。

服务器.R:

load("rapmsu.rda")
convMSU <- function(locus="Os02g0677300") {
  if (nchar(locus)==12) {
    return(rapmsu[rapmsu$rap==locus,])
  } else {
    return(NULL)
  }
}
convRap <- function(locus="LOC_Os03g57940") {
  if (nchar(locus)==14) {
    return(rapmsu[rapmsu$msu==locus,])
  } else {
    return(NULL)
  }
}
convID <- function(query="", text="") {
  if (query=="RAPdb Locus") {
    return(convMSU(text))
  } else if (query=="MSU Locus") {
    return(convRap(text))
  }
}

query.intext.conv <- c("Os02g0677300", "LOC_Os03g57940")
names(query.intext.conv) <- c("RAPdb Locus", "MSU Locus")

#### Shiny
shinyServer(function(input, output) {

  output$inTextconv <- renderUI({
    textInput("inTextconv", strong("Put your query here:"), 
            value=query.intext.conv[input$queryconv])
  })

  output$mytable10 = renderDataTable({
    convID(input$queryconv, input$inTextconv)
  }, options = list(aLengthMenu = 1, iDisplayLength = 1,
                  bFilter = FALSE, bAutoWidth = FALSE)
  )
})
Run Code Online (Sandbox Code Playgroud)

ui.R:

shinyUI(fluidPage(  
  fluidRow(
    absolutePanel(
      br(),

      selectInput("queryconv", h4("* Convert ID of MSU genomic locus
                                  and RAPdb genomic locus"), 
                 choices=c("RAPdb Locus", "MSU Locus")),

      uiOutput("inTextconv"),

      tabsetPanel(
          tabPanel(strong('Result'), dataTableOutput("mytable10"))
      ),

      br(),

      right=5, left=10
    )
  )
))
Run Code Online (Sandbox Code Playgroud)

变量“rapmsu”是一个数据框。

> head(rapmsu)
           rap            msu
1 Os01g0100100 LOC_Os01g01010
2 Os01g0100200 LOC_Os01g01019
3 Os01g0100300           None
4 Os01g0100400 LOC_Os01g01030
5 Os01g0100466           None
6 Os01g0100500 LOC_Os01g01040
Run Code Online (Sandbox Code Playgroud)

Por*_*hop 5

确保您的函数中包含所有测试用例。NULL首先测试NA和 然后进行评估nchar。这是您的函数之一的修改示例:

convMSU <- function(locus="Os02g0677300") {

  if(is.null(locus) || is.na(locus))
  {
    return()
  }

  else if (nchar(locus)==12) {
    return(rapmsu[rapmsu$rap==locus,])
  } 

  else {
    return()
  }
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我首先测试了 NULL 和 NA,然后评估了表达式。正如你的错误所说:argument is of length zero