I wrote a small Shiny application using renderUI
. It ran correctly but the R
console thrown out an error message
Error in if (nchar(locus) == 12) { : argument is of length zero
every time I ran this application.
Here are my scripts.
server.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)
)
})
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
)
)
))
The variable "rapmsu" is a data frame.
> 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