我的代码就像在我的闪亮应用中一样:
$(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)
答案 0 :(得分:5)
解决方案是使用闪亮的事件:
$(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);
});