Custom widget observer not fire

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?

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

You did provide substantial code, but better if its embedded in a minimal app that can be run without forum user writing boilerplate around it. The forum posts permit editing so feel free to use that feature.

Here is simple application with my widget, sorry it's not minimal example because I don't have time to make it simple. The problem is in shiny and in R. I think this is a bug but first I asked here.

The code is my widget (shiny custom input) with CSS and JS and some utilities that are in my code base.

Almost the same code was working fine when data send from JS to R was in different format. it may be the issue with shiny not detecting that data was changed, because it serlized/deserialize the data in wrong way.

If your issue is not with any other behaviour, but only the datastructor being returned being complete, accurate but unusual. It seems to me you might dput() the return object here so we can understand it and wrangle it.

this is output of dput:

c(comparison.group = "10", comparison.session = "1", comparison.sessionGroup = "3", 
comparison.tissue = "1000", reference.group = "10", reference.session = "1", 
reference.sessionGroup = "3", reference.tissue = "1000")

In JS it's {comparison: {group: 1}, reference: {group: 2}} and both fields have the same key/value pairs but with different values. Previous data was:
{comparison: [1,2,3], reference: [3,4,5]} and it was working fine.

Sorry the github repo was broken, just fixed so it fetch the front-end files. It now works.

its a named character vector so passing it as a param to tibble::enframe() will result in a data.frame.

Ok, the error was in my code, few issues, onChange in selectize is not jQuery object and I was returning same data in getValue.

Can this thread be deleted? it will be of any use to anyone.