Hello,
I don't fully understand what your goal is, but I can give you a few pointers. I do recommend that you create a Shiny reprex so you can more easily show what's going on and have a 'working' example of the issue. This guide will help you create one:
If you only want to only filter on columns with factors, your first choices of selectInput "sel1" should only be those columns (so ColA and ColB). You can then have your selectInput "b" update its choices based on the choice of "sel1".
I created a dummy example to illustrate:
library(shiny)
ui <- fluidPage(
selectInput("filter1","Variables",choices = c(),width = 150),
selectInput("filter2","Variables",choices = c(),width = 150)
)
server <- function(input, output, session) {
#Generate some data
myData = data.frame(ColA = LETTERS[sample(1:5, 10, replace = T)],
ColB = LETTERS[sample(6:10, 10, replace = T)],
ColC= runif(10))
#For filter 1, only use the columns with factors
updateSelectInput(session, "filter1",
choices = colnames(myData)[sapply(myData, class) == "factor"])
#Based on filter 1, show the factors in filter 2
observeEvent(input$filter1, {
updateSelectInput(session, "filter2",
choices = myData[,input$filter1])
}, ignoreInit = T)
}
shinyApp(ui, server)
NOTE: the ignoreInit = T
for the second filter's observeEvent is needed to prevent an error occurring when there is nothing assigned yet to filter 1 when the app loads.
Again, if this is not answering your question, please create a reprex using the guide.
Kind regards,
PJ