ebailey78 / shinyBS

Twitter Bootstrap Components for Shiny
182 stars 47 forks source link

bsTypeAhead won't display choices unless updateTypeAhead is called #2

Closed ncocacola closed 10 years ago

ncocacola commented 10 years ago

I've been trying to use bsTypeAhead in one of my Shiny Apps, but no matter what I try, bsTypeAhead won't display a choice of inputs when I type something.

I've tried to investigate the issue and found out that it doesn't work unless I call updateTypeAhead immediately after declaring the bsTypeAhead.

This doesn't work:

# ui.R
pollutants <- c('Acetone', 'Acrolein', 'Benzene', 'Benzyl Chloride')
bsTypeAhead("ta1", label = "Pollutants:", choices = pollutants, items=4)

But this does:

# ui.R
pollutants <- c('Acetone', 'Acrolein', 'Benzene', 'Benzyl Chloride')
bsTypeAhead("ta1", label = "TypeAhead:", choices = pollutants, items=4),
htmlOutput("updateTA")
# server.R
output$updateTA <- renderText({
    pollutants <- c('Acetone', 'Acrolein', 'Benzene', 'Benzyl Chloride')
    updateTypeAhead(session, inputId = "ta1", label = "TypeAhead:", choices=pollutants)
    return("")
})

You can replicate this problem by commenting out eval(parse(text=code)) in the TypeAhead section of your demo (to prevent updateTypeAhead from running).

Am I doing something wrong, or is this how bsTypeAhead is supposed to be used?

ebailey78 commented 10 years ago

That was definitely a bug. I've run into several similar problems. The only fix that I can think of off the top of my head is to have the typeahead initialized with javascript rather than with the data- tags. I've changed bsTypeahead so that it inserts a small script after the typeahead input that initializes the typeahead. I've pushed the change to the master branch. It seems to be working for me but let me know if you have any problems...

ncocacola commented 10 years ago

It works great, thank you very much! :)

ghost commented 10 years ago

It still doesn't work under Shiny Server or Rstudio Server built-in httpserver