0

I have a Juypter Notebook cell with some code (not mine) that generates a Bokeh plot. Last command in the cell is a Bokeh show() command. What I want is for the plot to appear in the output cell below, and then to be able to continue running subsequent cells in the notebook.

What happens instead is that when I run the cell the plot appears below, but the cell with the code continues to run (asterisk in the left-hand brackets) and never stops. So I can't continue to run any other cells unless I click the stop button (which leaves the plot intact in the output cell, but follows it with many lines of error trace-back messages).

My understanding is that executing the output_notebook() function should result in show() giving the behavior I want, as described here:

https://docs.bokeh.org/en/latest/docs/user_guide/notebook.html

In their screenshot, the cell with the show() command has clearly finished running (no asterisk).

I'm not sure if it makes any difference, but in my case I am running the notebook on a remote server and using port-forwarding to view it on my laptop computer browser.

Does anyone know how I can get the show() command to finish running?

For reference, this is the code:

# Use the PCA projection
dset = proj_pca

# Select the dimensions in the projection
dim1 = 0
dim2 = 1

p = figure(plot_width=945, plot_height=560)
p.title.text = 'PCA projection: PC' + str(dim1+1) + ' vs PC' + str(dim2+1)

for cont in continents: 
    for pop in pop_by_continent[cont]:
        projections_within_population = dset[indices_of_population_members[pop]]
        p.circle(projections_within_population[:,dim1], projections_within_population[:,dim2], 
                 legend=name_by_code[pop], color = color_dict[pop])

#p.legend.visible = False
p.legend.location = "top_center"
p.legend.click_policy="hide"

output_file("interactive_pca.html", title="PCA projection")
output_notebook()

#save(p)
show(p)
mcrepeau
  • 23
  • 2
  • 5
  • This looks like bog standard Bokeh code for a notebook, so my guess is that it is something to do with your specific circumstance. Do notebooks with bokeh plots work locally? What version of Bokeh are you using? Does `output_notebook` (which presumably is called above) report success? – bigreddot Dec 11 '19 at 21:45
  • After some experimenting, I was able to solve the problem by removing the output_file() command. This is with Bokeh 0.13.0 – mcrepeau Dec 12 '19 at 00:19
  • It would be unusual to try to use them together simultaneously. – bigreddot Dec 12 '19 at 05:36
  • Yes. Hazard of borrowing and modifying other people's code that I don't fully understand! Investigation reveals that output_file() pops up a new browser tab that renders the static html file, while output_notebook() renders the image in the Jupyter Notebook output cell. Having both clearly creates a problem when the show() function is called. – mcrepeau Dec 12 '19 at 19:41
  • 1
    Also of note, you _can_ switch between the two modes within a single Jupyter Notebook, but you have to use the reset_output() function in between. See here: https://stackoverflow.com/questions/25936005/can-one-switch-between-output-notebook-and-output-file-within-an-ipython-noteboo – mcrepeau Dec 12 '19 at 19:42

0 Answers0