Update selectizeinput while typing (AWS CloudSearch)

I'm attempting to build a selectizeinput to fetch choices / options from a remote data source. In the years since this post was made it looks like most cloud providers and developers don't agree this is a very good way to fetch data for a search, unless you're Github I guess.

That being said I'm trying to write a possible solution using AWS CloudSearch + paws R package to create large searchable, data indexes, in a safe way.

library(shiny)
library(paws)

ui <- basicPage(
  tagList(
    selectizeInput(
      inputId = "search",
      label = "The Search Label",
      choices = NULL
    )
  )
)

server <- function(input, output, session) {
  svc <- cloudsearchdomain(
    config = list(
      credentials = list(
        creds = list(
          access_key_id = "X",
          secret_access_key = "X"
        )
      ),
      endpoint = "X",
      region = "X"
    )
  )

  myChoices <- reactive({
    data <- svc$search(
      query = input$search,
      size = 20,
      queryParser = "simple"
    )

    l <- length(data[["hits"]][["hit"]])

    if(l > 0){
      search_field <- lapply(1:l, function(x){
        data[["hits"]][["hit"]][[x]][["fields"]][["name"]]
      })
    }else{
      search_field <- " "
    }
    search_field <- unlist(search_field)
  })
  
  observe({
    updateSelectizeInput(
      session,
      'search',
      choices = myChoices(),
      selected = character(0),
      server = TRUE
    )
  })
}

shinyApp(ui, server)

The search to svc$search works just fine when I execute it from the console, however I can't seem to figure out how I can update a selectizeinput's choices while I type to a remote source.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.