Selectinput() with multiple=TRUE in Shiny app , only responds when i choose values serially

i have a simple shiny app and i want to create data table which will provide the rows based on the name i choose in my selectinput(). While it works normally when i choose names one after the other(first,second,third...etc) it does not respond when i choose first name, then third name, then second etc. Any suggestions?

nba <- data.frame(
  player = c("James", "Durant", "Curry", "Harden", "Paul", "Wade"), 
  team = c("CLEOH", "GSWOAK", "GSWOAK", "HOUTX", "HOUTX", "CLEOH"),
  day1points = c("25","23","30","41","26","20"), 
  day2points = c("24","25","33","45","26","23"),
  rating=c("1","2","3","4","5","1")
)

ui.r

library(shiny)
library(DT)
ui <- navbarPage(
  title="SADDAS",
           sidebarLayout(
             sidebarPanel(uiOutput("var1_select")),
             mainPanel(tableOutput("reportOutput"))
))

server.r

server <- function(input, output) {
  output$var1_select<-renderUI({
    selectInput("ind_var_select","Select Names", choices =c(as.character(nba[,1] )),multiple = TRUE,selected = nba[1,1])
  })
  output$reportOutput = renderTable(
    {subset(nba[,1:3],player==input$ind_var_select)},
    options = list(scrollX = TRUE)
  )
}
2 Likes

Try to replace player==input$ind_var_select, with
player %in% input$ind_var_select. It should do the job..!!

5 Likes

Yes, this is the problem. Here's working code that will do what you need (reformatted slightly, too to help me read it):

library(shiny)
library(DT)

nba <- data.frame(
  player = c("James", "Durant", "Curry", "Harden", "Paul", "Wade"), 
  team = c("CLEOH", "GSWOAK", "GSWOAK", "HOUTX", "HOUTX", "CLEOH"),
  day1points = c("25","23","30","41","26","20"), 
  day2points = c("24","25","33","45","26","23"),
  rating=c("1","2","3","4","5","1")
)

ui <- navbarPage(
  title="SADDAS",
  sidebarLayout(
    sidebarPanel(uiOutput("var1_select")),
    mainPanel(tableOutput("reportOutput"))
  ))

server <- function(input, output) {
  output$var1_select <- renderUI({
    selectInput(
      "ind_var_select",
      "Select Names", 
      choices = as.character(nba[,1] ),
      multiple = TRUE,
      selected = nba[1,1]
      )
  })
  
  output$reportOutput = renderTable({
    # Filter it
    subset(nba[,1:3], player %in% input$ind_var_select)
  }, options = list(scrollX = TRUE))
}
2 Likes

shinyApp(ui,server) and the end would complete the code :slight_smile: