posit-dev / positron

Positron, a next-generation data science IDE
Other
2.39k stars 70 forks source link

Plain bokeh plots _after_ loading `hvplot` don't work. #4541

Closed nstrayer closed 1 week ago

nstrayer commented 2 weeks ago

Interpreter details:

Python 3.12.4 (but it doesn't really matter)

Describe the issue:

When you try and render a plot in the console using bokeh after you've loaded the hvplot library, it wont display.

Steps to reproduce the issue:

Run the following code in the console in order:

import hvplot.pandas
import pandas as pd
pd.DataFrame(dict(x=[1,2,3], y=[4,5,6])).hvplot.scatter(x="x", y="y")

from bokeh.plotting import figure, show
p = figure(title="Simple line example", x_axis_label='x', y_axis_label='y')
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label="Temp.", line_width=2)
show(p)

Expected or desired behavior:

The bokeh plot should show up.

Were there any error messages in the UI, Output panel, or Developer Tools console?

The following gets logged to the console

Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing

What's happening

When we added support for bokeh plots in #4178 we did so under the idea that bokeh was sending plots out by packaging up an html file and asking python to show it. Turns out that importing hvplot switches how bokeh renders plots, so now it sends a message with mime types application/vnd.bokehjs_exec.v0+json and application/javascript. We almost assuredly will need to rig up a multi-message replay system for this case for bokeh like we did with hvplot as this message assumes that bokeh is loaded on the page already.

testlabauto commented 2 weeks ago

Note to @testlabauto and @jonvanausdeln : Verify with automation and with a release build on Ubuntu. I saw some tough to explain differences between the release and dev build on Ubuntu.

seeM commented 1 week ago

We almost assuredly will need to rig up a multi-message replay system for this case for bokeh like we did with hvplot as this message assumes that bokeh is loaded on the page already.

Is it possible to reverse whatever hvplot is doing? Maybe there's a setting in Bokeh for this that we can override? Might be worth figuring out what exactly hvplot is doing to change Bokeh's behavior.

nstrayer commented 1 week ago

I tracked down why the output is switching. Thanks to the crazy dependency chain of the holoviews/hvplot/panel ecosystem it was difficult.

hvplot loads holoviews, which in turn, because it detects positron as an ipython kernel, runs a helper function created in panel that turns on output_notebook() in bokeh. https://github.com/holoviz/panel/blob/main/panel/io/notebook.py#L438

testlabauto commented 1 week ago

Verified Fixed

Positron Version(s) : main on Sep6
OS Version          : OSX

Test scenario(s)

Verified in automation

Link(s) to TestRail test cases run or created: Already automated