I'm trying to use a shiny selectInput("sort_var", "Sort on..", choices = colnames(df))
value inside a dplyr pipe so the dataframe is sorted by the selected variable with arrange
, but I'm struggling to follow the recommended tidyeval quoting and unquoting of inputs because the shiny input is already quoted and so the following code doesn't seem to work...
sorted_df <- reactive({
sort <- quo(input$sort_var)
df %>%
arrange(!!sort)
})
The following code does what I'm looking for..
sorted_df <- reactive({
df %>%
arrange(.[[grep(paste0("^", input$sort_var, "$"), colnames(df))]])
})
But I'd be interested to know if there is a workable tidyeval procedure for this.
Cheers!