Unable to reproduce a minimal example of selectizeUpdate in R Shiny

Viewed 34

I'm trying to reproduce a minimal example of selectizeInput from here. I want to show "MPG:value" next to the car name in bold using render method (the last example of the page) but nothing shows up in the UI. How can I do this?

Here's the code:

ui.R

 fluidPage(
  fluidRow(
    column(width = 5,
      selectizeInput('cars', label = NULL, choices = NULL, options = list(
        placeholder = 'Type a car name, e.g. Mazda', maxOptions = 5)
      )
    ),
  )
)

server.R

function(input, output, session) {
  updateSelectizeInput(session, 'cars', server = TRUE,
                       choices = cbind(name = rownames(mtcars), mtcars),
                        options = list(render = I(
                          '{
                              option: function(item, escape) {
                                return "<div><strong>" + escape(item.name) + "</strong> (" +
                                 "MPG: " + item.mpg + ") </div>";
                              }
                          }'))
  )
}
1 Answers

If we add the searchField, labelField to 'name', it would work

server = function(input, output, session) {
  updateSelectizeInput(session, 'cars', server = TRUE,
                       choices = cbind(name = rownames(mtcars), mtcars),
                       options = list(labelField = 'name', searchField = 'name', valueField = 'name', render = I(
                         '{
                              option: function(item, escape) {
                                return "<div><strong>" + escape(item.name) + "</strong> (" +
                                 "MPG: " + item.mpg + ") </div>";
                              }
                          }'))
  )
}

-testing

shinyApp(ui = ui, server = server)

enter image description here

Related