holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.13k stars 109 forks source link

Support reactive expressions in arguments and options #1288

Open jbednar opened 8 months ago

jbednar commented 8 months ago
Software version info
Python : 3.11.5 (main, Sep 11 2023, 08:31:25) [Clang 14.0.6 ] Operating system : macOS-14.0-arm64-arm-64bit Panel comms : default holoviews : 1.18.3 bokeh : 3.3.4 colorcet : 3.0.1 dask : 2023.6.0 datashader : 0.16.0 geoviews : 1.11.0 hvplot : 0.9.2 IPython : 8.15.0 jupyterlab : 4.0.11 matplotlib : 3.8.0 notebook : 7.0.6 numba : 0.58.0 numpy : 1.24.3 pandas : 2.1.1 panel : 1.3.1 param : 2.0.1 pillow : 10.0.1 pyarrow : 11.0.0 pyviz_comms : 2.3.0 scipy : 1.11.3 spatialpandas : 0.4.9 xarray : 2023.6.0

I would expect reactive expressions (pn.rx(), param.rx()) to be treated the same as Panel Widgets and Param Parameters (i.e., support for all Reactive References), but only widgets and parameters seem to be accepted:

import hvplot.pandas, pandas as pd, panel as pn
df = pd.DataFrame([6,2,9], [1,2,3])
e = pn.widgets.IntSlider(value=2, start=1, end=10, name="e")
pn.Column(e,df.hvplot.line(line_width=e))
image
pn.Column(e,df.hvplot.line(line_width=e.param.value))
image
pn.Column(e,df.hvplot.line(line_width=e.rx()))

AbbreviatedException: TypeError: __str__ returned non-string (type rx)
jbednar commented 8 months ago

For completeness, note that .apply.opts() can also be used successfully here:

import hvplot.pandas, pandas as pd, panel as pn
df = pd.DataFrame([6,2,9], [1,2,3])
e = pn.widgets.IntSlider(value=2, start=1, end=10, name="e")
pn.Column(e, df.hvplot.line().apply.opts(line_width=e))
image
maximlt commented 8 months ago

Taking the initial example, we can see the object returned is not a HoloViews element but a Panel object: image

I think we weren't very happy with non-HoloViews objects returned by .hvplot() calls (there might be an issue on that topic). I also have some vague memory of us talking about deprecating some of that functionality, since it can be done with .interactive():

image

It seems to me this issue is part of the greater issue of figuring out what to do with .interactive() now param.rx exists that I put on hvPlot roadmap's for this year. Cc'ing @philippjfr since he may have some ideas 🙃

philippjfr commented 8 months ago

Taking the initial example, we can see the object returned is not a HoloViews element but a Panel object:

This was an exceptionally bad decision on my part and should be undone. I'm not sure how to undo it cleanly though.

maximlt commented 8 months ago

should be undone

Returning a Panel object, or allowing .hvplot() to accept widgets/parameters?

philippjfr commented 8 months ago

Returning a Panel objects; eventually we do want to accepts reactive references and then apply them with .apply.opts().

maximlt commented 8 months ago

Ok, noted.

I'm not sure how to undo it cleanly though.

Perhaps with starting to emit a deprecation warning for the current behavior, and add a parameter (maybe global) for users to opt in the new behavior.