Reputation: 19
I am writing a R shiny app where I have a Ui. R which provides the user to select multiple options, each of the option is mapped to to read a tab delimited file which has two columns data.
All I want it to have a main table with tabs where one of the tab prints the tables (as selected by the user) one below the other.
Here Is my code:
Ui.R
shinyUI(pageWithSidebar(
headerPanel(strong(" ", style="color:black"), windowTitle="T2P"),
sidebarPanel(
tags$head(
tags$style(type='text/css', "input { width: 100px; }"),# control numericInput box ,
tags$style(type='text/css', "select,textarea,.jslider,.well { background-color: #F0F0F0; } ")
),
selectInput("var",
label = (strong("Choose Feature DataSets for Analysis", style="color:black")),
choices = c(" ","Gene Ontology", "PFAM",
"SecondaryStructures", "PeptideStats"),
selected = "", multiple=TRUE)
),
mainPanel(
tags$head(
tags$style(type = "text/css", "a{color: black;}")
),
list(tags$head(tags$style("body {background-color: #F5F5F5; }"))),
##
tabsetPanel(id="tabSelected",
tabPanel("Introduction", style="color:black",
h1("Introduction"),
textOutput("myselection"),
br()
# tableOutput("myGO")
),
tabPanel("Table", style="color:black",
h1("Table"),
# tableOutput("myselection2Table")
tableOutput("myGO"),
# br(),
tableOutput("myPFAM")
)
)
)
)
)
server.R
shinyServer(
function(input, output)
{
output$myGO <- renderTable({
myGOdata <- {
if (input$var %in% "Gene Ontology")
{
data.frame(read.table("GO.txt", sep="\t",header=TRUE))
}
}
})
output$myPFAM <- renderTable({
if (input$var %in% "PFAM")
{
data.frame(read.table("PFAM.txt", sep="\t",header=TRUE))
}
})
}
)
Upvotes: 0
Views: 1839
Reputation: 7830
In your conditions "if (input$var %in% "PFAM")" you test one by one, if each element of "input$var" is in "PFAM", then it returns one boolean for each elements.
If
statement can't deal with an expression which returns several booleans, that's why you probably get a warning like this : Warning in if (input$var %in% "Gene Ontology") { :
the condition has length > 1 and only the first element will be used
Reverse your test, it should be : "if ("Gene Ontology" %in% input$var)". You need to test if "Gene Ontology" is in "input$var" and not the contrary.
Normaly, it should work now.
Upvotes: 3