Learn R Programming

shinyBS (version 0.20)

bsTypeAhead: Twitter Bootstrap TypeAheads

Description

Functions to add and update Twitter Bootstrap TypeAhead text inputs in shiny.

Usage

bsTypeAhead(inputId, label, value = "", choices, items = 8, minLength = 1)
bsNavTypeAhead(inputId, label, value = "", choices, 
               items = 8, minLength = 1, width = NULL)
updateTypeAhead(session, inputId, label=NULL, value=NULL, choices=NULL)

Arguments

session
The session object passed to function given to shinyServer
inputId
Input variable to assign the control's value to
label
The label that will appear on the object
value
The value to set for the input object
choices
A list of choices that will appear as the user types.
items
The maximum number of typeahead choices to show at a given time.
minLength
The minimum number of characters the user must type before the typeahead choices appear.
width
The width, in pixels, of the text input

Details

bsTypeAhead creates a text box that will start displaying items in choices as the user types similar inputs. It looks and behaves as a textInput object otherwise. bsNavTypeAhead is meant for use inside a bsNav object. The main difference is that the value of label is placed into the placeholder attribute of the input object. This saves space in the navbar. updateNavBar will update a bsTypeAhead or bsNavTypeAhead object, allowing the user to change the label, value, or choices.

References

http://getbootstrap.com/2.3.2/javascript.html{Typeahead for Twitter Bootstrap 2.3.2}

Examples

Run this code
## In ui.R
  ## Create a standalone typeahead that contains a predefined list of fruits
  ## as choices
  bsTypeAhead(inputId = "ta1", label = "Choose a fruit", choices = fruits)
  ## Create the same typeahead in a navbar, with a width of 100px.
  bsNavTypeAhead(inputId = "ta2", label = "Fruits", choices = fruits, width = 100)
  
  ## In server.R
  ## Update the second typeAhead to a list of vegetables, update label to reflect change
  updateTypeAhead("ta2", choices=veggies, label="Vegetables")

Run the code above in your browser using DataLab