0

I am trying to create 4 radio buttons against each row in an R Shiny renderDataTable. I did some research and found this code working fine for my purposes:

  output$featureset = DT::renderDataTable(
  m, escape = FALSE, selection = 'none', server = FALSE,
  options = list(dom = 't', paging = FALSE, ordering = FALSE)
  ,
  callback = JS("table.rows().every(function(i, tab, row) {
                  var $this = $(this.node());
                  $this.attr('id', this.data()[0]);
                  $this.addClass('shiny-input-radiogroup');
});
                  Shiny.unbindAll(table.table().node());
                  Shiny.bindAll(table.table().node());"
  )
)

But, before creating this dynamic dataset and generating these radio buttons, I need to create a spark connection. Connection creation and dynamic loading of the data takes a bit of time, so I thought I'd put them at a button click. So, I introduced a button and created a connection, and loaded the data behind that button click(eventReactive).

Now, my problem is that I am not sure how I make 'renderDataTable' dependent on that button click. I tried putting in an if condition like so:

  output$featureset = DT::renderDataTable({
    if (is.null(conn_spark())) {print('commmon')}
      dataset
    },escape = FALSE, selection = 'none', server = FALSE, options = list(dom = 't', paging = FALSE, ordering = FALSE),
                      callback = JS("table.rows().every(function(i, tab, row) {
                                      var $this = $(this.node());
                                      $this.attr('id', this.data()[0]);
                                      $this.addClass('shiny-input-radiogroup');
                    });
                                      Shiny.unbindAll(table.table().node());
                                      Shiny.bindAll(table.table().node());"
                      )
  ) 

But, for some reason its not working. I don't see anything created. I'd appreciate any help. Thanks.

Please feel free to let me know if there's anything that can help but I haven't included in my question. I'd be glad to do so.

Ahsan
  • 551
  • 2
  • 5
  • 18
  • 3
    Hi Ahsan. In general it is a good idea to add a minimal reproducible example, I recently created some guidelines for `shiny`-related questions [here](https://stackoverflow.com/questions/48343080/how-to-create-a-good-shiny-reproducible-example/48343110#48343110). On one hand, it can help you debug, since you could just replace the entire code in `eventReactive` with for example `mtcars`. If the problem persists, we now know it has nothing to do with spark. On the other hand, it makes it much easier for others to help you tackle the issue if they can easily reproduce the behavior. – Florian Jan 22 '18 at 06:15
  • Thanks Florian for the suggestion. I tried it with mtcars, and it worked, problem seemed to be with the spark somewhere else. Thanks. – Ahsan Feb 03 '18 at 03:55

0 Answers0