0
votes

I have a data frame (df) with column names var1 and var2 are factors. I’m trying to create a dynamic list of variable 2 based on the input chosen by user for variable 1.

When I run the following statement at the command line in R: sort(unique(df$var2[df$var1 %in% c("a", "b")])), I get the result as expected, an output is list of factor variables that meets the criteria, in this case x, y.

However, when I use the following code in my shiny app, it returns the indexes of x and y. Would anyone know what may be the issue as to why the indexes are returned and how I might be able to resolve it? Any suggestions would be greatly appreciated!

UI:

uiOutput("var2Output")

Server:

output$var2Output <- renderUI({
   selectInput("var2Input", "Var2",
               (sort(unique(df$var2[df$var1 %in% c("a", "b")]))),
               selected = "x")
})
1

1 Answers

0
votes

The catch is, the choices parameter for selectInput has the following documentation

List of values to select from. If elements of the list are named then that name rather than the value is displayed to the user.

So you need to remove the names.