0

I try to make a selection menu like this:

Interactively change the selectInput choices

And everything works well with the exception of one thing: Instead to get the values (like McDonald), I get the indices although I did nothing different (see picture link below). Where could be my mistake?

Picture

Here my global.R:

partners<- read.csv("genes.csv", header=TRUE, fill=TRUE)

server.R

shinyServer(function(input, output) {

#subTable
searchResult<- reactive({
subset(partners, grepl(input$nameSearch, partners$name))
})

output$searchResults <- renderTable({ 
searchResult()[,1]
})


output$selectUI <- renderUI({ 
selectizeInput("partnerName", "Click in and select", choices=searchResult()[,1], multiple=TRUE )
})
})

ui.R

library(shiny)

shinyUI(pageWithSidebar(
# Give the page a title
titlePanel("Tilte"),

sidebarPanel(

textInput("nameSearch", "Search for name", "Blah"),
htmlOutput("selectUI"),
br(),
submitButton("Update View"),
br()

),
# Create a spot for the barplot
mainPanel(
textOutput("text"),
plotOutput("plot")  
)
)
)
Community
  • 1
  • 1
Yosi
  • 11
  • 2

1 Answers1

0

I think you are not getting indices, but rather the integer representation of a factor. Check the class of partners[,1]. Try

output$selectUI <- renderUI({ 
    selectizeInput("partnerName", "Click in and select",
                   choices=as.character(searchResult()[,1]), multiple=TRUE )
})

You could possibly add the stringsAsFactors=FALSE option when you read the data as well.

Rorschach
  • 31,301
  • 5
  • 78
  • 129
  • Many thanks, that was the problem and solved the problem! I'm new in R and not so familiar with this factor-"problem". I'm really glad that you gave me the tip! – Yosi Oct 19 '15 at 16:53
  • No problem, factors are confusing at first, they are stored as integers to save space, and each integer has a label. – Rorschach Oct 19 '15 at 16:58