Working out ways to send functions from R to JS