Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plots from hvplot don't work #3880

Closed
david-cortes opened this issue Jul 4, 2024 · 4 comments
Closed

Plots from hvplot don't work #3880

david-cortes opened this issue Jul 4, 2024 · 4 comments
Assignees
Labels
area: plots Issues related to Plots category. bug Something isn't working lang: python support theme: app builder

Comments

@david-cortes
Copy link

Positron Version:

Positron Version: 2024.07.0 build 14
Code - OSS Version: 1.90.0
Commit: b750305d0e9079e1a6d4e0b1d78daa70964b0cb8
Date: 2024-07-04T03:06:07.448Z
Electron: 29.4.0
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Linux x64 6.1.0-22-amd64

Steps to reproduce the issue:

  1. Create a plot with hvplot.
import polars as pl
import hvplot.polars
from sklearn.datasets import load_iris
df = load_iris(as_frame=True)["data"]
df = pl.DataFrame(df)
df["sepal length (cm)"].hvplot.hist()

What did you expect to happen?

Should show the plot in the plotting panel and let me play with it, like in the regular Jupyter extension:
image

Actual behavior

Generates a series of non-viewable plots in the plots pane, but the actual plot doesn't show:
image

Were there any error messages in the output or Developer Tools console?

No

@david-cortes david-cortes added the bug Something isn't working label Jul 4, 2024
@seeM seeM added lang: python area: plots Issues related to Plots category. labels Jul 5, 2024
@seeM
Copy link
Contributor

seeM commented Jul 5, 2024

Thank you for the report! I'm able to repro this on macOS.

@nstrayer
Copy link
Contributor

Once #4118 is finished, this may be taken care of since bokeh is the plotting library underpinning hvplot.

@nstrayer
Copy link
Contributor

I do get errors in the webview developer tools related to missing resources.
image

@nstrayer nstrayer self-assigned this Aug 7, 2024
nstrayer added a commit that referenced this issue Aug 15, 2024
Addresses #3880 

### What
This PR adds a new service that intercepts messages from holoviz plots
so they can be replayed when a plot is rendered into the plots pane.

### Why
This is necessary because holoviz sends preliminary messages that load
assets for displaying plots and these messages need to be sent to the
plot webview along with the plotting message when rendering the plot or
else various assets will not be available.

This is not a problem in notebooks because all output is rendered into a
single large "backlayer" webview and thus the preliminary messages are
properly "remembered."

This is specific to holoviz/holoviews plots right now but there is a
decent chance this pattern of remembering prerequisite messages and
replaying them to the output webview will be useful for other
libraries/situations.

### Limitations
Right now we store the prereq messages in memory on the UI thread. This
is nice and lightweight _but_ has the problem of forgetting those
messages if the user reloads the front end. Since hvplots doesn't replay
the asset loading messages on reload the plots won't work until the
session is restarted. We could do something like make the storage of
prereq messages use a non-ui layer cache, but I'm not convinced it will
be a big issue.


### Results
__hvplots now work in the plots pane__
<img width="1352" alt="image"
src="https://github.com/user-attachments/assets/d60dd978-8be9-4cc8-8827-71a5956d9fff">


__Behavior in notebooks should be unchanged__
<img width="953" alt="image"
src="https://github.com/user-attachments/assets/8bd307d1-1b46-4c12-886c-ea2293aedac1">

### QA Notes

This code will create a simple hvplot scatter plot. It should work in
the plots pane.
```python
import polars as pl
import hvplot
import hvplot.polars
pl.DataFrame(dict(x=[1,2,3], y=[4,5,6])).hvplot.scatter(x="x", y="y")
```

The same code should work in a notebook. (Although even before this PR I
noticed sometimes it was flakey which I think is due to how hvplots
loads assets).


<!--
  Add additional information for QA on how to validate the change,
  paying special attention to the level of risk, adjacent areas that
  could be affected by the change, and any important contextual
  information not present in the linked issues.
-->

---------

Signed-off-by: Nick Strayer <nick.strayer@posit.co>
Co-authored-by: Wasim Lorgat <mwlorgat@gmail.com>
@jonvanausdeln jonvanausdeln added the needs automated test Issue is candidate for automated test label Aug 19, 2024
@jonvanausdeln
Copy link
Contributor

Verified Fixed

Positron Version(s) : 2024.08.0-48
OS Version(s) : Windows 11, MacOS 14

Test scenario(s)

Using original code, the plot shows as expected using:

  • Python File
  • Notebook
  • in Console

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2024
@jonvanausdeln jonvanausdeln removed the needs automated test Issue is candidate for automated test label Sep 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: plots Issues related to Plots category. bug Something isn't working lang: python support theme: app builder
Projects
None yet
Development

No branches or pull requests

6 participants