0

I want the selectInput to show "Option1" and "Option2" not "1" and "2".

server.R

library(shiny)
shinyServer(function(input, output) {

 ## Uncomment one of the below options (single #)

  ## This option works but the data.frame only has 1 level, mine has 20 levels
  #my_list <-  as.character(c("Option1","Option2"))

  ## This option does not work and is as close as I can get to recreating my error
  #my_list <-  data.frame(c("Option1","Option2"))

  ## This option does not work as ds has Factor w/ 20 levels, 20 obs. of 1 variable
  #ds <- getData() 
  #ds <- data.frame(ds)
  #my_list <-  as.character(c(ds))


  output$my_list_select <- renderUI({
    selectInput(inputId = "select_input1", 
                label = h6("My List"), 
                choice = (my_list), 
                selected = 2)
  })
})

ui.R

library(shiny)
shinyUI(
  fluidPage(
    mainPanel(
      fluidRow(        
        column(4,
               uiOutput("my_list_select")
        )))))

Edition: At agstudy's suggestion I have rewritten the above so that it is as reproducible as possible ( I have a MYSQL query running on a local DB in getData() so what I can reproduce is limited).

Thanks for your time.

ldr9007
  • 1
  • 2
  • I guess, `getData` returns factors. Try `my_list <- as.character(getData())` – agstudy Jan 06 '15 at 11:10
  • Yes it does return factors. Using `as.character()` results in c(1, 2, ... 20) being the one and only choice. – ldr9007 Jan 06 '15 at 11:19
  • 1
    I don't get your point. Very hard(waste of time) to help you without a reproducible example. Please, Add the result of `as.character(getData())` to your question. – agstudy Jan 06 '15 at 11:27
  • Plase use 'dput(ds)' and show your data! Also the example is not a reproducible as we cannot see the actual source of error – Pork Chop Jan 06 '15 at 12:26

1 Answers1

0

The solution was my_list <- as.vector(ds$symbol).

Found the answer thanks to Extract Column from data.frame as a Vector

Many many thanks for your help.

Community
  • 1
  • 1
ldr9007
  • 1
  • 2