Learn R Programming

dqshiny (version 0.0.3)

autocomplete_input: Creates an autocomplete text input field

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

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

Examples

Run this code
# NOT RUN {
## 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))
    })
  }
)

}
# }

Run the code above in your browser using DataLab