Skip to content

Rewrite interactive API without holoviews dependency #5138

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

Merged
merged 38 commits into from
Sep 23, 2023

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Jun 19, 2023

This came out of some discussions with @jbednar on Friday. With the advent of more React-like APIs in Python we are in a place where we don't have a good way to declare standalone reactive variables, such as in this Solara example:

FxpgKt6XgAAipl-

Initially I was thinking that we should be able to declare unbound param.Parameter instances which we could pass around but then I noted that we already have a very powerful reactive data structure in our ecosystem, namely the hvplot interactive API, which does not only support reactivity but also allows operator chaining and much more.

One of the main obstacles with .interactive is that it depended on dim expressions in HoloViews as a consequence of which it was specialized to support only objects that a holoviews.Dataset can wrap. Since I always had planned to rewrite .interactive to be independent of HoloViews AND to allow it to actually chain and store intermediates.

Unlike the hvplot implementation this implementation does not store the full chain of operations in hv.dim objects, instead we build up a chain of interactive objects each of which references the previous one. This means that intermediate results can be cached.

Migration plan

The plan is to implement a generic version of interactive here but allow it to be extended in all the ways that are required for hvPlot to handle plotting and add special handling for DataFrame and xarray Dataset/DataArray types.

Examples

Counter app:

count = pn.expression(0)
pn.Column(
    pn.widgets.Button(name='Click me!', on_click=lambda e: count.set(count.eval()+1)),
    pn.expression('Click count is {}').format(count)
)

ToDo

  • Ensure all types of reactive objects are supported
    • param.Parameter
    • panel.widgets.Widget
    • Bound functions and methods
    • Other interactive objects
  • Decide on top-level API, i.e. is it pn.ref
  • Add tests
  • Add documentation

@codecov
Copy link

codecov bot commented Jun 19, 2023

Codecov Report

Merging #5138 (4a8d620) into main (2ff66b7) will decrease coverage by 2.49%.
Report is 1 commits behind head on main.
The diff coverage is 74.44%.

@@            Coverage Diff             @@
##             main    #5138      +/-   ##
==========================================
- Coverage   83.60%   81.12%   -2.49%     
==========================================
  Files         276      277       +1     
  Lines       40251    40387     +136     
==========================================
- Hits        33653    32764     -889     
- Misses       6598     7623    +1025     
Flag Coverage Δ
ui-tests 41.36% <36.29%> (-0.11%) ⬇️
unitexamples-tests 69.98% <74.44%> (-2.48%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
panel/config.py 69.24% <10.00%> (-1.09%) ⬇️
panel/io/notebook.py 36.46% <20.00%> (-7.98%) ⬇️
panel/pane/ipywidget.py 51.89% <42.85%> (-1.95%) ⬇️
panel/pane/holoviews.py 79.25% <60.00%> (-0.32%) ⬇️
panel/depends.py 70.00% <66.66%> (-5.68%) ⬇️
panel/param.py 85.66% <70.86%> (-2.82%) ⬇️
panel/util/__init__.py 87.18% <80.00%> (-0.54%) ⬇️
panel/util/checks.py 87.87% <80.00%> (-0.65%) ⬇️
panel/widgets/base.py 92.10% <85.71%> (-0.42%) ⬇️
panel/tests/test_expression.py 98.46% <98.46%> (ø)
... and 5 more

... and 17 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jbednar
Copy link
Member

jbednar commented Jun 19, 2023

Sounds great to me; it's been really tricky to explain why .interactive is in hvPlot rather than in Panel. Just to be clear, with this support pn.interactive(df) would be roughly equivalent to hvplot's df.interactive()?

@philippjfr
Copy link
Member Author

I have now split out an interactive_base which effectively only uses APIs that will be available in param 2.0 and interactive extends the base class adding all the Panel based display machinery. This means, in principle, interactive_base could live in param.

@philippjfr philippjfr merged commit 7088c68 into main Sep 23, 2023
@philippjfr philippjfr deleted the interactive_rewrite branch September 23, 2023 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants