updateTabItems in JavaScript


#1

I'm trying to write a callback function for a DT:datatable which does an updateTabItems in response to a double click on a row. The double click response looks like:

                callback = JS('
                table.on("dblclick.dt","tr", function() {
                    var data=table.row(this).data();
                    alert("You clicked on  a row!");} 
                )
              ') 

which works, but I don't really want an alert, I want the equivalent of updateTabItems(session,"id",newtab)
But the callback only accepts JavaScript. Anyone know how to do this in JavaScript?
thanks!


#2

Hi @andrew57jm, not sure how to do this directly in JS, but you could add a line in your JS code that calls R and from there call the updateTabItems.
See also the documentation

callback = JS('
                table.on("dblclick.dt","tr", function() {
                    var data=table.row(this).data();
                    Shiny.onInputChange("updateTab", data);} 
                )
              ')

 observeEvent(input$updateTab, {
    updateTabItems(session, "id", newtab)
})

#3

Perfect. Works like a charm. Strange side effect however, When I include the double click callback and try and pipe the output of the DT::datatable to a formatStyle function, the table never displays any data. There must be some interaction between the two mechanisms. I'll leave that for another day as I can probably do my column formatting in the JavaScript callback.