hvplots only work when executed line by line
System details:
Positron and OS details:
Positron Version: 2025.02.0 (system setup) build 39 Code - OSS Version: 1.95.0 Commit: 968a8acfff4300e6f4cf1cc8004507b97aa8e78b Date: 2025-01-13T02:52:35.414Z Electron: 32.2.1 Chromium: 128.0.6613.186 Node.js: 20.18.0 V8: 12.8.374.38-electron.0 OS: Windows_NT x64 10.0.26100
Interpreter details:
Python 3.10.10
Describe the issue:
This just started occurring on 1/14/2025. There seems to be some package dependency that updated, but we can't figure out which. It is similar to #4891
A simple python script to generate a plot using hvplot will only show if the script is executed line by line. It will not show if the entire file is sent to the console via the "run" button nor if you copy the entire block and past it in into the console.
Steps to reproduce the issue:
import hvplot.pandas
import pandas as pd
hvplot.extension('plotly')
pd.DataFrame(dict(x=[1,2,3], y=[4,5,6])).hvplot.scatter(x="x", y="y")
- Create a new venv
- Create new python file with above example code
- Click run button to "Run Python file in console"
- The plot does not display correctly.
- Copy entire contents of the file
- Paste into console and hit
enterto execute entire block - The plot does not display correctly.
Only by executing line by line (using ctrl+enter) will get the plot to show
Expected or desired behavior:
Plot to show when executing entire file.
Were there any error messages in the UI, Output panel, or Developer Tools console?
QA Notes
See https://github.com/posit-dev/positron/pull/5993 for disabled tests. Re-enable when this is resolved
I just updated hvplot to see if it would do the same thing. It seems to only fail when using Run Python File in Console. It was the same failure as before updating hvplot.
Although, I added a line of code and couldn't get the execute selection to show the plot:
import hvplot.pandas
import pandas as pd
hvplot.extension('plotly')
pd.DataFrame(dict(x=[1,2,3], y=[4,5,6])).hvplot.scatter(x="x", y="y")
x=25
I used Ctrl+Enter to run the selection and sourcing the file. Only running line-by-line works. It does appear to execute the entire block since x shows up in the Variables pane but no plot is displayed.
https://github.com/posit-dev/positron/blob/271dbb526528aa8146b9001589136dda7ca26ba1/src/vs/workbench/contrib/positronWebviewPreloads/browser/utils.ts#L33-L38
It seems to be something with checking the mime types. We get the holoviews mime type but the check requires more than that to trigger displaying the plot.
These are the mime types when executing the file:
-
application/javascript -
application/vnd.holoviews_load.v0+json
There's also a second message that comes in with these mime types:
-
text/html -
application/vnd.holoviews_load.v0+json
So the file execution doesn't have the right mime types to display the plot and the message from the backend is effectively dropped.
This is the only place that includes the holoviews exec mime type but it doesn't seem to add in text/plain.
https://github.com/holoviz/holoviews/blob/e1f584b4bf2398113c652f0c52c93660959488a9/holoviews/plotting/renderer.py#L381
@nstrayer I'm not really sure the reason we only render when receiving all three mime types but that only happens when running the code line-by-line.
Note there might be different-but-still-bad behavior now: https://github.com/posit-dev/positron/issues/7465
There seems to be a few issues going on here.
- As for the plot-not-showing-up. It's because when you click the run button it does
%run "./my-script.py"which is a fundamentally different (non-interactive) way of running code according to jupyter. In this case there is no display message because it doesn't make sense to do that. That being said, I'm not sure this is the desirable behavior for positron. - The mime-type rendering behavior. In this case it's because the only reliable way we found to detect a holoviews display message was the presence of all those mime-types. We need to "detect" this message because we need to replay all the dependency messages from before to get the correct js environment for the plot to actually render in our isolated webview plots-pane.
- The lots of empty plots issue is a legitimate brand-new issue that is super annoying. They must have changed their message formats so now we don't hide the output from the pre-req messages like we used to.
This is the fun stuff with holoviews/hvplot: they send so many messages layering on dependencies etc that I'm afraid we will always be chasing down things like this unless we can come up with a more robust solution (or they decide to use standard best-practices for loading assets.)
Because hvplot works when you execute the lines in an "interactive" mode which is expected behavior given how we treat the "run file in console" button, i'm thinking of closing this issue in favor of opening one about changing the run-file button. Just to make sure - @jonvanausdeln , hvplot works when you run it any other way than sourcing the file with the run button, right? (The extra plots is a separate (and annoying) issue.)
@jonvanausdeln , hvplot works when you run it any other way than sourcing the file with the run button, right? (The extra plots is a separate (and annoying) issue.
Correct, if I run line-by-line it works
Made new issue that gets at the heart of this problem. If this behavior remains or I misunderstood, please reopen!
Noticed this behavior was occurring as described when running multiple lines of code in the console, as described, and exactly as our skipped hvplot test currently does.
This issue has been driving me crazy. I think I have tracked the problem down to a global state variable that hvplots uses to detect if the plotly extension was run in the same line as the hvplot import. https://github.com/holoviz/holoviews/blob/main/holoviews/ipython/init.py#L147 When we run line-by-line this attribute never gets set so we get the proper resources loaded. It's worth noting that this also causes issues in normal notebooks where if you run the same code again it won't display the plot (most of the time at least.)
Verified Fixed
Positron Version(s) : 2025.06.0-156
OS Version : OSX
Test scenario(s)
Normal plot with:
import hvplot.pandas
import pandas as pd
hvplot.extension('plotly')
pd.DataFrame(dict(x=[1,2,3], y=[4,5,6])).hvplot.scatter(x="x", y="y")
Link(s) to TestRail test cases run or created: