0

I have a data frame (df) with has four columns (alpha, beta, gamma and delta). Data in each of the columns is an integer. I’m writing a shiny app in which when the user chooses one of the options (options 1 -4) it matches to an appropriate column name and few manipulations are performed using dplyr package.

For some reason, when I use : “b[match(input$defInput, a)] %in% c(0:14)”, it does not work, though when I manually check “alpha %in% c(0:14)”, it works fine.

I checked the classes of the arguments, and they seem to match. Any suggestions to resolve it would be greatly appreciated!

server <- function(input, output, session) {
    filtered <- reactive({
        a = c ("Option1", "Option2", "Option3", "Option4")
        b = c ("alpha", "beta", "gamma", "delta")
             df %>% 
            filter (b[match(input$defInput, a)] %in% c(0:14))
})

server <- function(input, output, session) {
    filtered <- reactive({
        a = c ("Option1", "Option2", "Option3", "Option4")
        b = c ("alpha", "beta", "gamma", "delta")
             df %>% 
            filter (alpha %in% c(0:14))
})
xineers
  • 109
  • 2
  • 2
  • 6
  • `b` is not a column in the data frame `df`. So, what are you trying to filter? – Gopala Apr 22 '16 at 17:14
  • Perhaps you can post a reproducible example and others can use to help with working code. In the meantime, you may want to check: http://stackoverflow.com/questions/26492280/non-standard-evaluation-nse-in-dplyrs-filter-pulling-data-from-mysql – Gopala Apr 22 '16 at 17:28
  • assigned vector b to include the names of the column. b[match(option1, a)] = alpha; b[match(option2, a)] = beta; Idea was to use – xineers Apr 22 '16 at 17:29
  • thanks Gopala for the link and help..will use lazy eval to assign the column name – xineers Apr 22 '16 at 17:32
  • Following Code worked – xineers Apr 22 '16 at 20:56
  • server <- function(input, output, session) { filtered <- reactive({ a = c ("Option1", "Option2", "Option3", "Option4") b = c ("alpha", "beta", "gamma", "delta") df %>% filter_(interp(~ y %in% c(0:14), y = as.name(b[match(input$defInput, a)]))) }) – xineers Apr 22 '16 at 20:57
  • You don't really need to maintain `b` in my opinion. Something like `names(.)` or `names(df)` should work since your `b` is a vector of names. That way, you are not hard coding it. – Gopala Apr 22 '16 at 22:24

0 Answers0