Connect Typeahead text input with 2 vectors of different size in shiny

shiny

#1

Hi i want to connect the 2 dropdown selectinputs which contain one vector of differnet size each one, with typeahead text input in a way that when i choose a Name to have all the Company names that this person (Name) works. (assume that every person works to all companies). The problem is that the vector “Names” is of different size than the vector " Companies" and i want to have a -one to many-connection and not -one on one- as in the shiny example. If the selectinputs is not a good idea i would like just to type the Name in the typeahead and then take all the company names.

ui.r

library(shiny)
library(shinysky)
shinyUI(basicPage(headerPanel("ShinySky Examples"),  br(),
tabsetPanel(
  tabPanel("Typeahead",
           h4("Typeahead Text Input "),
           div(class="row-fluid ", div(class="well container-fluid",
            div(class="container span3",
            helpText("Type 'name' or '2' to see the features. "),
            textInput.typeahead(
            id="thti"
            ,placeholder="type 'name' or '2'"
            ,local=data.frame(name=c("name1","name2"),info=c("info1","info2"))
            #,Names<-c("a","b","c","d","e","f","g","h","i","j")
            #,Companies<-c("k","l","m","n","o","q","r","s","t","u")
            ,valueKey = "name"
            ,tokens=c(1,2)
            ,template = HTML("<p class='repo-language'>{{info}}</p> <p class='repo-name'>{{name}}</p> <p class='repo-description'>You need to learn more CSS to customize this further</p>")
            ),
            actionButton("update_typeahead_btn","Update Typeahead", styleclass= "primary")
           ),
           div(class="container span9"
               ,shinyalert("shinyalert3")
           ))
           )),
  selectInput("exp", label = "Expert",
              choices = c(unique(as.character(Names ))),multiple = FALSE,selected = "a" ),
  selectInput("com", label = "Company",
              choices = c(unique(as.character(Companies ))),multiple = FALSE,selected = "k" )


)))

server.r

options(shiny.trace = F)  # cahnge to T for trace
require(shiny)
require(shinysky)

shinyServer(function(input, output, session) {
  Names<-c("a","b","c","d","e","f","g","h","i","j")
  Companies<-c("k","l","m","n","o","q","r","s","t","u","v","w","x","y","z")
  # typeahead
  observe({
    input$thti
    showshinyalert(session, "shinyalert3", sprintf("Typeahead Text Input Value: '%s'", 
                                                   input$thti), "error")
  })
  # typeahead
  observe({
    if (input$update_typeahead_btn == 0) {
      return()
    }
    dataset <- data.frame(firstname = c("ZJ", "Mitchell"), lastname = c("Dai", "Joblin"))
    valueKey <- "lastname"
    tokens <- c("zd", "mj", dataset$firstname)
    template <- HTML("First Name: <em>{{firstname}}</em> Last Name: <em>{{lastname}}</em>")
    updateTextInput.typeahead(session, "thti", dataset, valueKey, tokens, template, 
                              placeholder = "type 'm' or 'z' to see the updated table")
  })
})