Search code examples
rshinyexpss

Passing variable names into fre command


I'm trying to pass set of variables into select input, and use its names to expss::fre command.

I have object with column names and its labels like 'myvars':

a1_1, "Do you like apples?"
a1_2, "Do you like oranges?"

I'm using them:

selectInput(vars, "Select variable", myvars)

Then, in 'server' section i would like to use it for generating simple frequency table.

output$view <- renderTable( {
        fre(input$variable)
}

The problem is that in fre I have to pass variable with dataset name:

fre(data$a1_1)

So I tried with eval, quo, !!, paste0("data$",input$vars) and more, but didn't succeed.

when I try with switch:

switch(input$vars, "a1_1"=fre(data$a1_1), "a1_2"=fre(data$a1_2))

It works fine, but I need more flexible solution. How to do this well?


Solution

  • The following code should do the trick:

    output$view <- renderTable({
            fre(data[[input$vars]])
    })