Skip to content

Commit 4a648df

Browse files
committed
remove duplicated block in selectizeJSON, simply lab assignement logic
1 parent e8abf6c commit 4a648df

File tree

1 file changed

+2
-23
lines changed

1 file changed

+2
-23
lines changed

R/update-input.R

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -651,16 +651,15 @@ updateSelectizeInput <- function(session, inputId, label = NULL, choices = NULL,
651651
# other objects return arbitrary JSON {x: , y: , foo: , ...}
652652
choices <- if (is.atomic(choices)) {
653653
# fast path
654-
lab <- if(is.null(names(choices))) {
655-
as.character(choices)
654+
if(is.null(names(choices))) {
655+
lab <- as.character(choices)
656656
} else {
657657
lab <- names(choices)
658658
# replace empty names like: choices = c(a = 1, 2)
659659
# int this case: names(choices) = c("a", "")
660660
# with replacement below choices will be: lab = c("a", "2")
661661
empty_names_indices <- lab == ""
662662
lab[empty_names_indices] <- as.character(choices[empty_names_indices])
663-
lab
664663
}
665664
# lab shold be lower-case for faster case-insensitive matching - grepl(... , fixed = TRUE)
666665
lab <- tolower(lab)
@@ -689,26 +688,6 @@ selectizeJSON <- function(data, req) {
689688
vfd <- query$value # the value field name
690689
sel <- attr(data, 'selected_value', exact = TRUE)
691690

692-
# convert a single vector to a data frame so it returns {label: , value: }
693-
# later in JSON; other objects return arbitrary JSON {x: , y: , foo: , ...}
694-
data <- if (is.atomic(data)) {
695-
696-
if(is.null(names(data))) {
697-
lab <- as.character(data)
698-
} else {
699-
lab <- names(data)
700-
# replace empty names like: data = c(a = 1, 2)
701-
# in this case: names(data) = c("a", "")
702-
# with replacement below choices will be: lab = c("a", "2")
703-
empty_names_indices <- lab == ""
704-
lab[empty_names_indices] <- as.character(data[empty_names_indices])
705-
}
706-
707-
data.frame(label = lab, value = data,
708-
stringsAsFactors = FALSE)
709-
} else {
710-
as.data.frame(data, stringsAsFactors = FALSE)
711-
}
712691
# start searching for keywords in all specified columns
713692
idx <- logical(nrow(data))
714693
if (length(key)) {

0 commit comments

Comments
 (0)