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

popup stream doesn't work with async #6388

Open
ahuang11 opened this issue Sep 25, 2024 · 2 comments · May be fixed by #6390
Open

popup stream doesn't work with async #6388

ahuang11 opened this issue Sep 25, 2024 · 2 comments · May be fixed by #6390
Labels
type: enhancement Minor feature or improvement to an existing feature

Comments

@ahuang11
Copy link
Collaborator

ahuang11 commented Sep 25, 2024

import numpy as np

import holoviews as hv

async def popup_stats(index):
    if not index:
        return
    return points.iloc[index].dframe().describe()


points = hv.Points(np.random.randn(1000, 2))

hv.streams.Selection1D(
    source=points,
    popup=popup_stats

)

points.opts(
    tools=["box_select", "lasso_select", "tap"],
    active_tools=["lasso_select"],
    size=6,
    color="black",
    fill_color=None,
    width=500,
    height=500
)
image

No error either.

@ahuang11 ahuang11 added the TRIAGE Needs triaging label Sep 25, 2024
@hoxbro
Copy link
Member

hoxbro commented Sep 26, 2024

We could raise an error here:

diff --git a/holoviews/plotting/bokeh/callbacks.py b/holoviews/plotting/bokeh/callbacks.py
index 89541b595..607ee4380 100644
--- a/holoviews/plotting/bokeh/callbacks.py
+++ b/holoviews/plotting/bokeh/callbacks.py
@@ -691,7 +691,11 @@ class PopupMixin:
         popup_is_callable = callable(popup)
         if popup_is_callable:
             with set_curdoc(self.plot.document):
-                popup = popup(**stream.contents)
+                import inspect
+                if inspect.iscoroutinefunction(popup):
+                    raise TypeError("Popup callback cannot be async")
+                else:
+                    popup = popup(**stream.contents)
 
         # If no popup is defined, hide the bokeh panel wrapper
         if popup is None:

@philippjfr
Copy link
Member

Would rather actually support async callbacks.

@ahuang11 ahuang11 added type: enhancement Minor feature or improvement to an existing feature and removed TRIAGE Needs triaging labels Sep 26, 2024
@ahuang11 ahuang11 linked a pull request Sep 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants