Thanks for the advice @cole. I tried implementing a simple server side selectize example but I'm currently stumped on the callback function. I want to send json from R to the custom load function. I'll keep working on it but thought I would post my example in case someone with more javascript experience might be able to spot the solution.
library(shiny)
library(babynames)
library(dplyr)
ui <- fluidPage(
tags$script('Shiny.addCustomMessageHandler("handler1", print_choices);
function print_choices(x){console.log(x);}'),
title = 'Server side Selectize example',
mainPanel(
selectizeInput('babyname', 'Baby Name', choices = '', options = list(
valueField = 'name', labelField = 'name', searchField = 'name',
loadThrottle = '500',
persist = FALSE,
options = list(),
create = FALSE,
render = I("{option: function(item, escape) {
return '<div>' + '<strong>' + escape(item.name) + '</strong>' + '</div>';
}}"),
load = I('function(query, callback) {
Shiny.onInputChange("query1", query);
return callback(); // here is where I need some help. Not sure how to pass the choices from R to this load function.
}')
))
)
)
server <- function(input, output, session) {
choices <- reactive({
req(input$query1)
babynames %>%
filter(stringr::str_detect(name, input$query1)) %>%
arrange(desc(n)) %>%
head(1000) %>% # cap at 1000 hits to send to browser
jsonlite::toJSON()
})
observe(session$sendCustomMessage("handler1", choices()))
}
shinyApp(ui = ui, server = server)