Description Usage Arguments Value Author(s) Examples
View source: R/autocomplete_input.R
autocomplete_input creates an autocomplete text input field, showing all possible options from a given list under the input while typing. Alternative to very slow select(ize) inputs for (very) large option lists.
update_autocomplete_input changes the value or the options of an autocomplete input element on the client side.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | autocomplete_input(
id,
label,
options,
value = "",
width = NULL,
placeholder = NULL,
max_options = 0,
hide_values = FALSE,
create = FALSE,
contains = FALSE
)
update_autocomplete_input(
session,
id,
label = NULL,
options = NULL,
max_options = NULL,
value = NULL,
placeholder = NULL,
hide_values = NULL,
create = NULL,
contains = NULL
)
|
id |
id of the element |
label |
label to show for the input, NULL for no label |
options |
list (or vector) of possible options |
value |
initial value |
width |
optional, the width of the input, see
|
placeholder |
optional character specifying the placeholder text |
max_options |
optional numeric specifying the maximum number of options to show (for performance reasons) |
hide_values |
optional boolean indicating whether to show values under labels or not |
create |
optional boolean to enable entering values not in the list |
contains |
optional boolean to enable searching in the middle of options |
session |
the shiny session object |
autocomplete_input: shiny input element
update_autocomplete_input: message to the client
richard.kunze
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ## Only run examples in interactive R sessions
if (interactive()) {
library(shiny)
opts <- sapply(1:100000, function(i) paste0(sample(letters, 9), collapse=""))
shinyApp(
ui = fluidPage(
fluidRow(
column(3,
autocomplete_input("auto1", "Unnamed:", opts, create = TRUE),
autocomplete_input("auto2", "Named:", max_options = 500,
structure(opts, names = opts[order(opts)]), contains = TRUE),
autocomplete_input("auto3", "Big data:", NULL, max_options = 1000,
placeholder = "Big data taking several seconds to load ..."),
actionButton("calc", "Calculate")
), column(3,
tags$label("Value:"), verbatimTextOutput("val1", placeholder = TRUE),
tags$label("Value:"), verbatimTextOutput("val2", placeholder = TRUE)
)
)
),
server = function(input, output, session) {
output$val1 <- renderText(as.character(input$auto1))
output$val2 <- renderText(as.character(input$auto2))
observeEvent(input$calc, {
Sys.sleep(3)
update_autocomplete_input(session, "auto3", placeholder = "Loaded!",
options = rownames(mtcars))
})
}
)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.