How to use shiny inputs as function parameters in R6 object-oriented environments?


I am developing a Shiny interface for an R script developed using R6. How can I pass Shiny input to a function?
Note: The code below will not work since it doesn't recognize input$user_f.

BSD$set("public", "", function(f = input$user_f) {  
  self$pars$f <- c(f, self$pars$f)[1]

Thanks so much!


Is input$user_f returning a character? If it is then that may be causing an issue when trying to use it with the $ operator. When I want to use an input like this, I do it using the [[ subsetting method. I am not really sure if this translate to R6 but this is what I mean:

BSD$set("public", "", function(f = input$user_f) {  
  self$pars[[f]] <- c(f, self$pars[[f]])[1]

Also, I am assuming that this is being run in your server code. Which, if not, would be a reason that input$user_f is not recognized.


It is returning a number. Yes, it is being run in my server code.

Here is the error I get:

Error in self$ : object 'input' not found

I also tried placing the R6 definitions in global.R and got the same error.
Any other ideas? Thanks!


Is the f in self$pars$f also referring to the function argument? of just the f at the beginning of your concatenation?

It may have something to do with the fact that you are using $ to select certain elements of your self object and input. You could try assigning input$user_f to a reactive value and passing the reactive value into the function. That doesn't seem like the most ideal scenario in my mind but it is worth trying to see if that is the issue.