Home > front end >  Update selectInput() by exlcluding values selected from another selectInput()
Update selectInput() by exlcluding values selected from another selectInput()

Time:03-29

In the shiny app below I want the selected values of the 1st selectInput() to be excluded from the 2nd selectInput() plus the one column I already exclude.

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    selectInput("col","Pick a column to change its name",
                choices = colnames(iris)[-c(1)]),
    uiOutput("second")
    
  ),
  dashboardBody(
    
    )
)

server <- function(input, output) {
  
output$second<-renderUI({
  selectInput("col2","Pick a column to change its name",
              choices = colnames(iris)[-c(1,input$col)])
})
 
  
}

shinyApp(ui, server)

CodePudding user response:

Maybe try to remove names in two steps

output$second<-renderUI({
  ex_names <- colnames(iris)[-1]
  ex_names <- ex_names[! ex_names %in% input$col]
  selectInput("col2","Pick a column to change its name", choices = ex_names)
})
  • Related