【发布时间】:2017-08-22 10:04:09
【问题描述】:
其实我在关注stackoverflow的这个问题
Embedding an R htmlwidget into existing webpage
上面的问题展示了两种嵌入图形的方法
- PHP
- jQuery
目前我正在使用 jQuery ajax 方法嵌入它可以工作的 json,但在第二个 ajax 请求图上没有更新。但是当我重新加载页面时,图表将被更新。所以我想在不重新加载整个页面的情况下更新图表。
** Updating data.json**
jQuery.ajax({
url : '/modules/multistep_form/plotlyjson/775_graph2_data.json',
beforeSend : function() {
},
type : 'POST',
cache : false,
success : function(data) {
//console.log(data);
// $("#data-json-graph2").text("");
console.log($("#data-json-graph2").text(""));
$("#data-json-graph2").append(JSON.stringify(data));
setTimeout(function(){
window.HTMLWidgets.staticRender();
Drupal.attachBehaviors();
}, 1000);
},
error : function(xhr, status, error) {
// executed if something went wrong during call
if (xhr.status > 0)
alert('got error: ' + status);
}
});
**Updating style.json**
jQuery.ajax({
url : '/modules/multistep_form/plotlyjson/775_graph2_style.json',
beforeSend : function() {
},
type : 'POST',
cache : false,
success : function(data) {
//console.log(data);
//$("#style-json-graph2").text("");
console.log($("#style-json-graph2").text(""));
$("#style-json-graph2").append(JSON.stringify(data));
setTimeout(function(){
window.HTMLWidgets.staticRender();
Drupal.attachBehaviors();
}, 1000);
},
error : function(xhr, status, error) {
// executed if something went wrong during call
if (xhr.status > 0)
alert('got error: ' + status);
}
});
【问题讨论】:
标签: jquery r plotly htmlwidgets