0

I want to subset a data frame based on userinput

...
df <- eventReactive(input$button,{ 
  df2 <- read.csv(foo(), sep = ";")
  df2$date <- as.Date.character(df2$date,  format = '%d.%m.%Y') 

  #input$Main2 element of (a,b,c)
  input1<- input$Main2

 #Does not work:
 df3 <- subset(df2, input1 %in% input$Main2_1)
 #Works:
  df3 <- subset(df2, a %in% input$Main2_1)

  df3
  })
....

Where input1 is a single variable name. It works fine if I directly write the variable name instead of input1.

1 Answer 1

1

You can try

df3 <- df2[df2[[input1 ]]%in% input$Main2_1,]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.