I have widget that return this data:
(function() {
var dataSelector = new Shiny.InputBinding();
$.extend(dataSelector, {
find: function(scope) {
return $(scope).find('.row-grid-control');
},
getValue: function(el) {
return $(el).find('.grid-control-pair').map(function() {
var self = $(this);
var result = {
comparison: {},
reference: {}
};
['comparison', 'reference'].forEach(function(prop) {
self.find('.' + prop + '-column').each(function() {
var self = $(this);
var name = self.data('name');
result[prop][name] = self.find('select').val();
});
});
return result;
}).get();
},
setValue: function(el, value) {
// TODO:
},
initialize: initialize,
subscribe: function(el, callback) {
console.log('subscribe');
// change event is broken with selectize it fire only once, we use onChange
// that trigger custom event update, to ensure that each change will trigger
// the event. see: https://stackoverflow.com/a/41557815
$(el).on("update.grid-control", callback);
},
unsubscribe: function(el) {
console.log('unsubscribe');
$(el).off(".grid-control");
}
});
It's a grid with 8 select elements and a button that add another 8 select inputs.
I initialize selectize inside init method, update is triggered in onChange of selectize, the same happen if I use $(el).on("change.grid-control", callback);
the JS code is correct, the code is executed no errors events are fired. The problem is in R.
The observer add to this input don't fire when I change the selects, it was working when I used different data in getValue. This is the output in R
server <- function(input, output, session) {
output$xxx <- renderUI({
avengersApps::gridSelect("fooBar", list(
groups = list(foo = 10, bar = 20),
sessions = list(hey = 1, yo = 2),
sessionGroups = list(hello = 3, world = 5),
tissue = list(t1 = 1000, t2 = 400)
))
})
count <- 0
observeEvent(input$fooBar, {
print('---------------------------')
print(paste("::", count))
print('---------------------------')
count <<- count + 1
print(input$fooBar)
})
}
It's some weird data structure and not list of lists.
[1] "---------------------------"
[1] ":: 0"
[1] "---------------------------"
comparison.group comparison.session comparison.sessionGroup
"10" "1" "3"
comparison.tissue reference.group reference.session
"1000" "10" "1"
reference.sessionGroup reference.tissue
"3" "1000"
How can make my custom input work?