0

Is there any reason this wouldn't work? I simply want to see which terms are found in the two selected columns. I figured intersect would do the job, but I'm not seeing results. If this looks alright, perhaps I have some other syntax error along the way? Do the inputs need to be in different sidebar panels?

selectInput("data1", "Choose you Input:", choices = colnames(data), selected = "PD.Risk.Factor"),

selectInput("data2", "Choose you Input:", choices = colnames(data), selected = "AD.Risk.Factor")),

Output:

p2 = intersect(x = input$data1, y = input$data2)
print(p2)
AJ Keefe
  • 3
  • 3

1 Answers1

0

Welcome to SO! Please provide a reprex the next time - this will help to get help.

For our problem. What your snippet does is to compare not the columns of your data frame but the the strings as returned by selectInput. What you want to do is to use these strings to retrieve the corresponding columns in the data.

library(shiny)
sample_dat <- data.frame(x = 1:10, y = 5:14, z = 9:18)

ui <- fluidPage(selectInput("col1", "Column 1:", names(sample_dat), "x"),
                selectInput("col2", "Column 1:", names(sample_dat), "y"),
                verbatimTextOutput("result"))

server <- function(input, output, session) {
   output$result <- renderPrint({
      list(on_strings = list(col1      = input$col1, 
                             col2      = input$col2, 
                             intersect = intersect(input$col1, input$col2)),
           on_cols    = list(col1      = input$col1, 
                             col2      = input$col2, 
                             intersect = intersect(sample_dat[[input$col1]], 
                                                   sample_dat[[input$col2]])))
   })
}

shinyApp(ui, server)

thothal
  • 16,690
  • 3
  • 36
  • 71