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

Ensure refs can be updated by watcher of the same parameter #929

Merged
merged 2 commits into from
May 2, 2024

Conversation

philippjfr
Copy link
Member

@hoxbro Please test and if possible add your test case.

@hoxbro
Copy link
Member

hoxbro commented Apr 2, 2024

It does not currently work for my case:

screenrecord-2024-04-02_16.35.19.mp4
import panel as pn
import param

pn.extension(notifications=True)

class T(param.Parameterized):
    lst = param.List(allow_refs=True, allow_None=True)

    @param.depends("lst")
    def test(self):
        items = [pn.widgets.TextAreaInput(value=str(i)) for i in range(5)]
        with param.discard_events(self):
            self.lst = pn.rx(items).rx.resolve()
        return pn.Column(*items)


t = T()

pn.widgets.Button(name="print", on_click=lambda e: pn.state.notifications.info(str(t.lst))).servable()
pn.panel(t.test).servable()

@philippjfr
Copy link
Member Author

Oh, that's not surprising, in fact that's the correct behavior, because what you're doing in that example is effectively resetting the lst list every time. If you don't want to do that you need to initialize the widgets given the lst values:

    @param.depends("lst")
    def test(self):
        lst = self.lst or range(5)
        items = [pn.widgets.TextAreaInput(value=str(i)) for i in lst]
        with param.discard_events(self):
            self.lst = pn.rx(items).rx.resolve()
        return pn.Column(*items)

@hoxbro
Copy link
Member

hoxbro commented Apr 2, 2024

Thank you. I will test it later.

@philippjfr philippjfr merged commit 3e1439d into main May 2, 2024
10 checks passed
@philippjfr philippjfr deleted the recursive_ref_sync branch May 2, 2024 08:41
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.

2 participants