Skip to content

Commit b4d20da

Browse files
author
Mark Needham
committed
cleaner way of writing to next cell
1 parent 335e5c6 commit b4d20da

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

generate_notebook.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def find_tag(file, tag):
180180

181181
neo_vis_js_cell = '''\
182182
%%javascript
183+
var output_area = this;
183184
requirejs(['neovis.js'], function(NeoVis){
184185
var config = {
185186
container_id: "viz",
@@ -200,8 +201,9 @@ def find_tag(file, tag):
200201
let command = "image_src = '" + imageSrc + "'";
201202
kernel.execute(command);
202203
203-
var nb = Jupyter.notebook;
204-
var cell = nb.select_next().get_selected_cell();
204+
var cell_element = output_area.element.parents('.cell');
205+
var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);
206+
var cell = Jupyter.notebook.get_cell(cell_idx+1);
205207
cell.set_text("HTML('<img id=\\"viz-image\\" width=\\"300px\\" src=\\"%s\\" />' % image_src)")
206208
cell.execute();
207209
});

notebooks/PageRank.ipynb

Lines changed: 20 additions & 16 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)