Filtering columns in ShinyApps SelectInput

Hello everyone,

Here is a sample of code in my ShinyApp:

output$datasetcolumn_outcome <- renderUI({
    chosen_dataset <- read.csv(paste("data-oh/", input$datasetname, sep = ""))
    selectInput("outcome_column", "Outcome variable choice:",
                # Only allow user to plot numerical data
                # Also filter some columns of the data
                Filter(function(x) 
                  (class(chosen_dataset[,match(x, names(chosen_dataset))]) == "numeric" || 
                     class(chosen_dataset[,match(x, names(chosen_dataset))]) == "integer") &&
                    (names(chosen_dataset)[match(x, names(chosen_dataset))] != "X" &&
                       names(chosen_dataset)[match(x, names(chosen_dataset))] != "FIPS"),
                  names(chosen_dataset)),

Here's how it works--the user selects a dataset from a list, which is chosen_dataset and comes from input$datasetname. Then the user uses a dropdown menu in the SelectInput to select a column of that dataset (which is a data.frame) to plot on a graph. However, the data frame's columns contain a lot of unwanted things, so I'd like to filter them out.

I want to be able to filter the columns such that the user can only select columns containing numbers, which I've already done. I also want to manually create a "blacklist" of columns that I don't want the user to be able to select, like the "X" and "FIPS" columns above. But I want to be able to create a vector of values, such as c("X", "FIPS"), and be able to filter out those. Something like this (not actual syntax):

output$datasetcolumn_outcome <- renderUI({
    chosen_dataset <- read.csv(paste("data-oh/", input$datasetname, sep = ""))
    blacklist <- c("X", "FIPS")
    selectInput("outcome_column", "Outcome variable choice:",
                # Only allow user to plot numerical data
                # Also filter some columns of the data
                Filter(function(x) 
                  (class(chosen_dataset[,match(x, names(chosen_dataset))]) == "numeric" || 
                     class(chosen_dataset[,match(x, names(chosen_dataset))]) == "integer") &&
                    (names(chosen_dataset)[match(x, names(chosen_dataset))] != blacklist)
                  names(chosen_dataset)),
    )
  })

Does anyone know how this might be done? Thanks!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.