jupyter笔记本无法在GitHub中呈现(jupyter notebook not rendering in GitHub gist)
我使用Jupyter笔记本创建并保存了一个笔记本。 然后我开始创建这个笔记本的github要点。 但是,笔记本没有在要点中呈现。 我只能看到原始代码。 我在下面列出了我的要点的链接:
https://gist.github.com/adikamath/26ae33d4fd613d716cdf01697130e675
我知道GitHub从一段时间以来就为ipnyb提供了高级支持,而且我不必使用像nbviewer这样的服务来查看它。 任何帮助表示赞赏。
I created and saved a notebook using Jupyter notebooks. I then proceeded to create a github gist of this notebook. However, the notebook is not being rendered in the gist. I can only see the raw code. I have included the link to my gist below:
https://gist.github.com/adikamath/26ae33d4fd613d716cdf01697130e675
I know that GitHub provides advanced support for ipnyb since some time now and I don't have to use a service like nbviewer to see it rendered. Any help is appreciated.
原文:https://stackoverflow.com/questions/47868625
最满意答案
听起来你可能需要按顺序而不是并行地进行ajax调用。
首先,将您的四个部分包装在
function() {...}
并从每个部分返回jqXHR
。function make_zero_rate_graph() { /*================================ = Zero Rate = ==================================*/ // 1-31 days return $.ajax({url: '/api/timebase/'+'{{ $cpe_mac }}/zero-rate'}).then(function(data) { if(data) { var gragh_ubb_0_rate = new FusionCharts({ 'type': 'bar2d', 'renderAt': 'gragh_ubb_0_rate', 'width': '100%', 'dataFormat': 'json', 'dataSource': { 'chart': $.extend({}, graph_ubb_configs, { 'caption': 'Zero Rated Traffic', 'subcaption': [data.m, data.d, data.y].join('/'), 'xaxisname': 'Bandwidth' }), 'data': [ { 'label': 'Uplink', 'value': +data.zero_rate_vlan.up_bytes / 1000000 }, { 'label': 'Downlink', 'value': +data.zero_rate_vlan.down_bytes / 1000000 } ], 'trendlines': t_line } }); gragh_ubb_0_rate.render(); } }); } function make_hour_graph() { /*=========================== = Hour = =============================*/ return $.ajax({url: '/api/timebase/'+'{{ $cpe_mac }}/hour'}).then(function(data) { var gragh_ubb_hour = new FusionCharts({ 'type': 'column2d', 'renderAt': 'gragh_ubb_hour', 'width': '100%', 'dataFormat': 'json', 'dataSource': { 'chart': $.extend({}, graph_ubb_configs, { 'caption': 'Daily Network Usage', 'subcaption': data.m + '/' + data.d + '/' + data.y + ' ( '+data.time+' )', 'xaxisname': 'Hours of Day' }), 'data': data.hour_p_ubb.slice(0, 24).map(function(item, i) { return { 'label': (i%12 || 12) + ' ' + ((i<12)?'AM':'PM'), 'value': (+item.up_bytes + +item.down_bytes) / 1000000 }); }), // 'trendlines': t_line } }); gragh_ubb_hour.render(); }); } function make_day_graph() { /*=========================== = DAY = =============================*/ // 1-31 days return $.ajax({url: '/api/timebase/'+'{{ $cpe_mac }}/day'}).then(function (data) { var c_val = 0; var gragh_ubb_day = new FusionCharts({ 'type': 'msline', 'renderAt': 'gragh_ubb_day', 'width': '100%', 'dataFormat': 'json', 'dataSource': { 'chart': $.extend({}, graph_ubb_configs, { 'caption': 'Monthly Network Usage', 'subcaption': data.m + '/' + data.d + '/' + data.y, 'xaxisname': 'Days of Month' }), 'categories': [{ 'category': data.day_p_ubb.map(function(_, i) { return { 'label': String(i+1) }; }) }], 'dataset': [{ 'data': data.day_p_ubb.map(function(item, i) { c_val += (i > 0 && i <= data.d) ? ((+item.up_bytes + +item.down_bytes) / 1000000) : 0; return { 'value': c_val }; }) }], 'trendlines': t_line } }); gragh_ubb_day.render(); }); } function make_month_graph() { /*============================ = Month = ==============================*/ var months = ['January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November','December']; return $.ajax({url: '/api/timebase/'+'{{ $cpe_mac }}/month'}).then(function (data) { var graph_month = new FusionCharts({ 'type': 'column2d', 'renderAt': 'graph_month', 'width': '100%', 'dataFormat': 'json', 'dataSource': { 'chart': $.extend({}, graph_ubb_configs, { 'caption': 'Yearly Network Usage', 'subcaption': [data.m, data.d, data.y].join('/'), 'xaxisname': 'Months of Year' }), 'data': data.month_p_ubb.slice(0,12).map(function(data, i) { return { 'label': months[i], 'value': (+data.up_bytes + +data.down_bytes) / 1000000 }; }), 'trendlines': t_line } }); graph_month.render(); }); }
函数内的代码已整理但未经过测试
有了这些功能,按顺序调用是微不足道的:
// List the functions in an array var fns = [ make_zero_rate_graph, make_hour_graph, make_day_graph, make_month_graph ]; // And build a then() chain by reducing the array, // see http://stackoverflow.com/documentation/javascript/231/promises/5917/#t=201612121359154320486 fns.reduce(function(jqPromise, fn) { return jqPromise.then(fn); }, $.when());
Sounds like you might need to make the ajax call sequentially instead of in-parallel.
First, wrap your four parts in
function() {...}
and returnjqXHR
from each.function make_zero_rate_graph() { /*================================ = Zero Rate = ==================================*/ // 1-31 days return $.ajax({url: '/api/timebase/'+'{{ $cpe_mac }}/zero-rate'}).then(function(data) { if(data) { var gragh_ubb_0_rate = new FusionCharts({ 'type': 'bar2d', 'renderAt': 'gragh_ubb_0_rate', 'width': '100%', 'dataFormat': 'json', 'dataSource': { 'chart': $.extend({}, graph_ubb_configs, { 'caption': 'Zero Rated Traffic', 'subcaption': [data.m, data.d, data.y].join('/'), 'xaxisname': 'Bandwidth' }), 'data': [ { 'label': 'Uplink', 'value': +data.zero_rate_vlan.up_bytes / 1000000 }, { 'label': 'Downlink', 'value': +data.zero_rate_vlan.down_bytes / 1000000 } ], 'trendlines': t_line } }); gragh_ubb_0_rate.render(); } }); } function make_hour_graph() { /*=========================== = Hour = =============================*/ return $.ajax({url: '/api/timebase/'+'{{ $cpe_mac }}/hour'}).then(function(data) { var gragh_ubb_hour = new FusionCharts({ 'type': 'column2d', 'renderAt': 'gragh_ubb_hour', 'width': '100%', 'dataFormat': 'json', 'dataSource': { 'chart': $.extend({}, graph_ubb_configs, { 'caption': 'Daily Network Usage', 'subcaption': data.m + '/' + data.d + '/' + data.y + ' ( '+data.time+' )', 'xaxisname': 'Hours of Day' }), 'data': data.hour_p_ubb.slice(0, 24).map(function(item, i) { return { 'label': (i%12 || 12) + ' ' + ((i<12)?'AM':'PM'), 'value': (+item.up_bytes + +item.down_bytes) / 1000000 }); }), // 'trendlines': t_line } }); gragh_ubb_hour.render(); }); } function make_day_graph() { /*=========================== = DAY = =============================*/ // 1-31 days return $.ajax({url: '/api/timebase/'+'{{ $cpe_mac }}/day'}).then(function (data) { var c_val = 0; var gragh_ubb_day = new FusionCharts({ 'type': 'msline', 'renderAt': 'gragh_ubb_day', 'width': '100%', 'dataFormat': 'json', 'dataSource': { 'chart': $.extend({}, graph_ubb_configs, { 'caption': 'Monthly Network Usage', 'subcaption': data.m + '/' + data.d + '/' + data.y, 'xaxisname': 'Days of Month' }), 'categories': [{ 'category': data.day_p_ubb.map(function(_, i) { return { 'label': String(i+1) }; }) }], 'dataset': [{ 'data': data.day_p_ubb.map(function(item, i) { c_val += (i > 0 && i <= data.d) ? ((+item.up_bytes + +item.down_bytes) / 1000000) : 0; return { 'value': c_val }; }) }], 'trendlines': t_line } }); gragh_ubb_day.render(); }); } function make_month_graph() { /*============================ = Month = ==============================*/ var months = ['January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November','December']; return $.ajax({url: '/api/timebase/'+'{{ $cpe_mac }}/month'}).then(function (data) { var graph_month = new FusionCharts({ 'type': 'column2d', 'renderAt': 'graph_month', 'width': '100%', 'dataFormat': 'json', 'dataSource': { 'chart': $.extend({}, graph_ubb_configs, { 'caption': 'Yearly Network Usage', 'subcaption': [data.m, data.d, data.y].join('/'), 'xaxisname': 'Months of Year' }), 'data': data.month_p_ubb.slice(0,12).map(function(data, i) { return { 'label': months[i], 'value': (+data.up_bytes + +data.down_bytes) / 1000000 }; }), 'trendlines': t_line } }); graph_month.render(); }); }
Code within the functions is tidied but not tested
With those functions in place, calling in sequence is trivial :
// List the functions in an array var fns = [ make_zero_rate_graph, make_hour_graph, make_day_graph, make_month_graph ]; // And build a then() chain by reducing the array, // see http://stackoverflow.com/documentation/javascript/231/promises/5917/#t=201612121359154320486 fns.reduce(function(jqPromise, fn) { return jqPromise.then(fn); }, $.when());
相关问答
更多-
通过本地客户端程序获取服务器mysql数据库信息[2023-04-27]
ajax -
XHR调用返回空(XHR calls return empty)[2022-05-09]
请求中有几件事要注意你正在做的事情。 您需要将status添加到200因为它是OK状态。 意味着您的请求会通过。 所以这部分将完全变成(this.readyState == 4 && this.status == 200) 。 您还需要从使用三重等号===更改为==因为您没有按TYPE进行比较,因为在JS中使用三重等号。 使用事件处理程序xhttp.onreadystatechange而不是xmr.readySate 。 这是一个Mozilla文档的链接 。 所以它应该成为: const xhttp = n ... -
我想通过添加一个回调函数并在成功函数中调用它,如下所示: success: function (response) { // callback(response); // }, I figured this out by adding a callback function and calling it within the success function, like so: success: function (response) { // callback(response); // ...
-
来自.trigger()上的jQuery文档: “事件对象总是作为第一个参数传递给事件处理程序,但是如果在.trigger()调用期间指定了其他参数,那么这些参数也会传递给处理程序。” 他们给出的例子是: $('#foo').bind('custom', function(event, param1, param2) { alert(param1 + "\n" + param2); }); $('#foo').trigger('custom', ['Custom', 'Event']); 所以我更新了: . ...
-
有两种解决方案: 1)将输入按钮类型从提交更改为按钮并再次尝试,因为您也通过单击提交表单,这可能导致问题。 2)在按钮单击上尝试event.preventDefault()。 Two solutions can be possible: 1) Change input button type from submit to button and try again, as you are also submitting form by clicking on it as well which might be ...
-
防止任何Ajax XHR GET在页面加载时返回500错误(Prevent Any Ajax XHR GETs returning 500 Error on page load)[2021-12-16]
听起来你可能需要按顺序而不是并行地进行ajax调用。 首先,将您的四个部分包装在function() {...}并从每个部分返回jqXHR 。 function make_zero_rate_graph() { /*================================ = Zero Rate = ==================================*/ // 1-31 days return $.a ... -
这一切都取决于你的后端是什么以及它是如何配置的。 它可以是VPS,它可以是专用服务器,也可以是云。 它可以有一个节点或几个节点。 它可以使用一个数据库,也可以分发数据库。 由于您注意到请求未同时处理,因此在您的情况下,服务器看起来像一个节点/一个进程/一个数据库。 或者它可能无法并行运行这两个操作,因为第二个请求的结果取决于第一个请求的结果。 It all depends on what your backend is and how it's configured. It could be a VPS, ...
-
从XHR / Ajax请求返回javascript的实际用例?(Practical use cases for returning javascript from an XHR/Ajax request?)[2022-08-14]
有时在服务器端“准备”JavaScript代码更方便。 您可以使用服务器的编程或脚本语言来生成代码,您可以使用数据库中的值填充它。 这样,大多数逻辑都发生在服务器上而不是客户端上。 但这真的是品味问题。 好吧,那不是一个真实世界的案例,但也许我的意见无论如何都是有帮助的。 Sometimes it is more convenient to "prepare" the JavaScript code on the server side. You can use the server's programmi ... -
铬的xhr请求太多了(too many xhr requests in chrome)[2022-07-14]
铬人们承认这是他们应该解决的问题: https : //code.google.com/p/chromium/issues/detail?id = 244910 ,但与此同时我使用jquery defer / resolve实现了限制以保持线程数低。 The chromium folks acknowledge this is something that they should fix: https://code.google.com/p/chromium/issues/detail?id=244910, ... -
在其他帖子中,人们建议使用Chrome CORS扩展程序,但自Chrome 48以来,所有CORS扩展程序似乎都停止了工作。 我在Visual Studio,Ripple Emulator和CORS / Cross Domain Ajax上发布了这个解决方法,但我将在下面再次概述: 在您的Chrome安装目录中 - 可能是C:\ Program Files(x86)\ Google \ Chrome \ Application - 创建chrome.exe的快捷方式 右键单击此快捷方式并选择“属性” 在“快 ...