Hey Maya! Not sure of the specific context, but if this is in a package, I would recommend defining the .onLoad function as follows:
shiny::registerInputHandler("maya.listOutput", function(value, ...) {
if (is.null(value)) {
return(value)
} else {
df <- shiny:::safeFromJSON(value) #convert to df -- this is essentially jsonlite::fromJSON
output <- split(df, seq(nrow(df))) #make a list of the form I think you want
attr(output, 'custom_attr') <- "test" #add custom attribute
return(output)
}
}, force = TRUE) #force = TRUE so error message doesn't appear when the input handler is already loaded
Then in your custom input binding, you would want to change your getValue method to this (just change the output to a JSON string):
getValue: function getValue(el) {
var value = [
{ id :1, name:"a" },
{ id:2, name:"b"},
{ id:3, name: "c"}
]
return(JSON.stringify(value));
},
The last step is to add a getType method in your custom binding. This will tell Shiny that it should return to the user what data as you defined it.
getType: function(el) {
return "maya.listOutput";
}
Sample output is below, and I believe it is equivalent to what you want. If not, you can change the expected output in your input handler.
[[1]]
id name
1 1 a
[[2]]
id name
2 2 b
[[3]]
id name
3 3 c
attr(,"custom_attr")
[1] "test"
This book was really helpful, as was the documentation for registerInputHandler. I hope that helps?!