2

When using selectize in R Shiny, is it possible to capture the currently highlighted element in the selection box? From the gallery:

selectizeInput(
    'e2', '2. Multi-select', choices = state.name, multiple = TRUE
  )

If after selecting a few States, one then clicked on 'California':

selectize selection

Is is possible to the selection of 'California' captured? Use case is to trigger a filter on a datatable so that it shows only information for the selected State.

2 Answers 2

Reset to default

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

2

You can write a custom JavaScript render.item method (not really pretty in one character string) :

library(shiny)

ui <- fluidPage(
  selectizeInput(
    inputId = 'select',
    label = '2. Multi-select',
    choices = state.name, 
    multiple = TRUE,
    options = list(
      render = I("{item: function(item, escape) {return '<div class=\"item\" onclick=\"Shiny.onInputChange(\\\'select_click\\\', \\\'' + escape(item.value) + '\\\')\">' + escape(item.value) + '</div>';}}")
    )
  ),
  tags$p("Selected:"),
  verbatimTextOutput("res_select"),
  tags$p("Click:"),
  verbatimTextOutput("res_click")
)

server <- function(input, output, session) {
  output$res_select <- renderPrint({
    input$select
  })
  output$res_click <- renderPrint({
    input$select_click
  })
}

shinyApp(ui, server)
1
  • Thanks so much that's awesome! Jun 10, 2019 at 19:24
0

Try this :
if it is to trigger a filter you would have to use it as an output to ( call it here )

 data1 <- <nameofyourfile>

 <dashboardbody options>.. .

column(2,selectizeInput('e2', '2. Multi-select', 
choices = state.name, multiple = TRUE)),uiOutput("StateOutput")

and this part goes in the server :

    output$StateOutput <- renderUI({ 
    data1 %>% filter(data1$<variablename> == input$e2Input)
    <insert the kind of filter you want to show based on the new data1>
                  })
1
  • This isnt what he wants, he needs an event capture trigger once the selection is highlights, blue
    – Pork Chop
    May 4, 2018 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.