I'm trying to update the choices for selectizeinput based on geocoding in the search field. The problem is that it doesn't register I've inputted anything, but when I hardcode a fake address on the server side it works. I've tried to make the choices reactive using tidygeocoder, but it doesn't register anytime I type anything into the search field.
Here is a reprex:
library(shiny)
library(shinyWidgets)
library(tidygeocoder)
ui <- fluidPage(
selectizeInput(
"search",
label = NULL,
choices = "",
multiple = FALSE,
selected = character(0),
options = list(allowEmptyOption = FALSE, placeholder = "SEARCH...")
)
)
server <- function(input, output, session) {
address_choices <- reactive({
tidygeocoder::geo(
input$search,
method = "osm",
limit = 5,
full_results = TRUE
)
})
observe({
req(address_choices())
current_selected <- isolate(input$search)
updateSelectizeInput(
session,
"search",
choices = address_choices()$display_name,
selected = current_selected,
server = TRUE
)
})
}
shinyApp(ui = ui, server = server)
Result:
It shows nothing no matter what I type in.
Hardcoded Address
The hardcoded version shows the intended result
address_choices <- reactive({
tidygeocoder::geo(
"110 Susan",
method = "osm",
limit = 5,
full_results = TRUE
)
})
Hardcoded Results
The drop down shows what should happen when I type "110 Susan"
I've also tried to include if else statements so that it doesn't run when input$search is blank (Which is the default), but that doesn't work. Maybe I shouldn't be using a reactive statement? I'm not quite sure. It just doesn't register input$search after I type.