Hi,
If I pass an option to renderDataTable that refers to a javascript function, I get the javascript error:
Uncaught TypeError: Object myCallbackFunction has no method 'apply'
For example,
If I have /tmp/demo.js that contains the following:
console.log("here we are in demo.js");
var myCallbackFunction = function( nRow, aData, iDisplayIndex ) {
console.log("in row callback function");
return nRow;
}
Then my R code like this (based on shiny datatables demo at
library(shiny)
addResourcePath("js", "/tmp")
runApp(list(
ui = basicPage(
tagList(singleton(
tags$script(src="js/demo.js")
)),
h2('The mtcars data'),
dataTableOutput('mytable')
),
server = function(input, output) {
output$mytable = renderDataTable({
mtcars
},
options=list(
fnRowCallback="myCallbackFunction"
)
)
}
))
If I run the R code, with the javascript console visible, I see:
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
Uncaught TypeError: Object myCallbackFunction has no method 'apply'
My guess is that shiny is creating some javascript that looks like this:
fnRowCallback: "myCallbackFunction"
But I want myCallbackFunction to not be in quotes because it is a function.
I tried changing the options to this (ugly):
options=list(
fnRowCallback="function(nRow,aData,iDisplayIndex) {console.log('hifromfunc');return nRow;}"
)
)
But that results in:
Uncaught TypeError: Object function(nRow,aData,iDisplayIndex) {console.log('hifromfunc');return nRow;} has no method 'apply'
Is there a way to pass a reference to an already-defined javascript function as an option to renderDataTable()?
Thanks,
Dan