Thought I might have found a solution with the function below:
returnOrder <- function(inputId, vars) {
tagList(
tags$head(tags$script(paste0("$(function() {$( '#",inputId,"' ).sortable({placeholder: 'ui-state-highlight'}); $( '#",inputId,"' ).disableSelection(); });"))),
tags$head(tags$script(src = 'js/sort.js')),
HTML(html_list(vars, inputId))
)
}
However, I still need to have the following in sort.js. Sorting works without suggesting the first line in the code above is working. However, for some reason the array of colnames is not passed back to Shiny unless the next bit is in sort.js.