-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working to integrate ThomasSiegmund's shinyTypeahead package to retur…
…n typeahead functionality.
- Loading branch information
Showing
9 changed files
with
674 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Package: shinyBS | ||
Type: Package | ||
Title: Twitter Bootstrap Components for Shiny | ||
Version: 0.61 | ||
Date: 2015-03-30 | ||
Version: 0.62 | ||
Date: 2015-03-31 | ||
Author: Eric Bailey | ||
Maintainer: Eric Bailey <[email protected]> | ||
Description: Adds additional Twitter Bootstrap components to Shiny. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#'bsTypeahead | ||
#' | ||
#'\code{typeaheadInput} creates a textinput with type ahead function buttons. | ||
#' | ||
#'@param inputId Input variable to assign the control's value to | ||
#'@param label Display label for the control | ||
#'@param value Initial value | ||
#'@param choices Array of strings to match against. Can also be JavaScript | ||
#' function. Use htmlwidgets::JS() to indicate JavaScript. The length of \code{choices} must no exceed 131370. | ||
#'@param items The max number of items to display in the dropdown. Can also be | ||
#' set to 'all' | ||
#'@param minLength The minimum character length needed before triggering | ||
#' autocomplete suggestions. You can set it to 0 so suggestion are shown even | ||
#' when there is no text when lookup function is called. | ||
#'@seealso \code{\link{updateTypeaheadInput}} | ||
#'@export | ||
bsTypeahead <- function(inputId, label, value = "", choices, items = 8, minLength = 1) { | ||
if(!is.null(choices)) { | ||
if(length(choices) > 131370) { | ||
warning("Due to a limitation of the Bootstrap2 Typeahead JavaScript library the length of 'choices' must not exceed 2 ^ 17 - 2!"); | ||
} | ||
} | ||
if(!'JS_EVAL' %in% class(choices)) { | ||
choices <- jsonlite::toJSON(choices); | ||
} | ||
typeahead <- shiny::tagList( | ||
shiny::div(class = 'form-group shiny-input-container', | ||
shiny::tags$label(label, `for` = inputId), | ||
shiny::tags$input(id = inputId, type="text", | ||
class="form-control shiny-bound-input typeahead", | ||
"data-provide" = "typeahead", autocomplete="off", | ||
value = value), | ||
shiny::tags$script(paste0("$('#", inputId, "').typeahead({source: ", choices, ", | ||
items: ", items, ", | ||
minLength: ", minLength, "})")) | ||
) | ||
) | ||
|
||
htmltools::attachDependencies(typeahead, typeaheadDep) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#'updateTypeahead | ||
#' | ||
#'\code{updateTypeahead} Update a typeaheadInput buttons. | ||
#'@param session The session object passed to function given to shinyServer. | ||
#'@param inputId Input variable to assign the control's value to | ||
#'@param label Display label for the control | ||
#'@param value Initial value | ||
#'@param choices Array of strings to match against. Can also be JavaScript | ||
#' function. Use htmlwidgets::JS() to indicate JavaScript. | ||
#'@seealso \code{\link{typeaheadInput}} | ||
#'@export | ||
updateTypeahead<- function(session, inputId, label=NULL, value=NULL, choices=NULL) { | ||
|
||
if(!is.null(choices)) { | ||
if(length(choices) > 131370) { | ||
warning("Due to a limitation of the Bootstrap2 Typeahead JavaScript library the length of 'choices' must not exceed 2 ^ 17 - 2!"); | ||
} | ||
} | ||
|
||
data <- dropNulls(list(id = inputId, label=label, value=value, choices=choices)) | ||
session$sendCustomMessage("typeaheadUpdate", data) | ||
|
||
} |
Oops, something went wrong.