autocomplete_input: Creates an autocomplete text input field

Description Usage Arguments Value Author(s) Examples

View source: R/autocomplete_input.R

Description

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.

Usage

1
2
3
4
5
6
autocomplete_input(id, label, options, value = "", width = NULL,
  placeholder = NULL, max_options = 0, hide_values = FALSE)

update_autocomplete_input(session, id, label = NULL, options = NULL,
  max_options = NULL, value = NULL, placeholder = NULL,
  hide_values = NULL)

Arguments

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 validateCssUnit

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

session

the shiny session object

Value

autocomplete_input: shiny input element

update_autocomplete_input: message to the client

Author(s)

richard.kunze

Examples

 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, max_options = 1000),
        autocomplete_input("auto2", "Named:", max_options = 1000,
          structure(opts, names = opts[order(opts)])),
        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))
    })
  }
)

}

dqshiny documentation built on May 2, 2019, 1:43 p.m.