我有像我的闪亮应用程序中的代码:
$(function() {
Shiny.onInputChange('initialHash', parseHashQuery());
});
function parseHashQuery() {
var result = {};
location.hash.replace(/^#/, '').split('&').filter(Boolean).forEach(function(part) {
var pair = part.split('=');
result[pair[0]] = pair[1];
});
return result;
}
但我有错误:
common.js:59 Uncaught TypeError: Shiny.onInputChange is not a function
at HTMLDocument.<anonymous> (common.js:59)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at Function.ready (jquery.min.js:2)
at HTMLDocument.K (jquery.min.js:2)
解决方法:
解决方案是使用闪亮的事件:
$(document).on('shiny:sessioninitialized', function(event) {
Shiny.onInputChange('initialHash', parseHashQuery());
});
已经定义了Shiny.onInputChange时执行的.
看看the source code,Shiny在jQuery ready函数中初始化但是超时:
$(function() {
// Init Shiny a little later than document ready, so user code can
// run first (i.e. to register bindings)
setTimeout(initShiny, 1);
});