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

Implement PyComponent #7051

Merged
merged 19 commits into from
Sep 3, 2024
Merged

Conversation

MarcSkovMadsen
Copy link
Collaborator

@MarcSkovMadsen MarcSkovMadsen commented Aug 1, 2024

I've been pointing out multiple times that its very hard to create real Panel widgets from the Viewer. Andrew then told me in #7030 that I should be using the CompositeWidget. I had not used that because the Viewer was originally added to enable me and others to create custom Panel components in general, so I thought that was the one I should use.

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 96.15385% with 3 lines in your changes missing coverage. Please review.

Project coverage is 81.82%. Comparing base (da68c8a) to head (75c08ea).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
panel/custom.py 94.44% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7051      +/-   ##
==========================================
- Coverage   82.23%   81.82%   -0.42%     
==========================================
  Files         334      337       +3     
  Lines       49925    50199     +274     
==========================================
+ Hits        41058    41077      +19     
- Misses       8867     9122     +255     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MarcSkovMadsen
Copy link
Collaborator Author

MarcSkovMadsen commented Aug 3, 2024

The content here is ready for review.

I believe though that it should be refactored using a new PyComponent class together with the BaseWidget class. The PyComponent should address the missing features of the Viewer and enable to create custom widgets by combining with BaseWidget.

@MarcSkovMadsen MarcSkovMadsen added this to the v1.5.0 milestone Aug 3, 2024
@philippjfr
Copy link
Member

-1 on actually documenting CompositeWidget, through composition this can now be achieved using Viewer + WidgetBase.

@philippjfr
Copy link
Member

Just read your last comment, glad we agree 😄

@philippjfr philippjfr changed the title Document CompositeWidget Implement PyComponent Aug 27, 2024
@philippjfr
Copy link
Member

Just had a look at the tutorial and imo it absolutely does not read like a tutorial. There's no real steps for the user to follow along except for pasting the entire thing into a file and then running it. It's really much closer to a how-to guide.

@MarcSkovMadsen
Copy link
Collaborator Author

Just had a look at the tutorial and imo it absolutely does not read like a tutorial. There's no real steps for the user to follow along except for pasting the entire thing into a file and then running it. It's really much closer to a how-to guide.

Fair point. I will try to improve it. Its just hard for me to see how I can break it further down as it consists of a single class definition and a single function.

@MarcSkovMadsen
Copy link
Collaborator Author

It would like to help finalize this, but its very unclear for me how to proceed.

It seems to me that the PyComponent is in a very preliminary state?

When I run

import panel as pn
import param

from panel.custom import PyComponent


class CounterButton(PyComponent):

    value = param.Integer()

    def __init__(self, **params):
        super().__init__()
        self._layout = pn.widgets.Button(
            name=self._button_name, on_click=self._on_click, **params
        )

    def _on_click(self, event):
        self.value += 1

    @param.depends("value")
    def _button_name(self):
        return f"count is {self.value}"

    def __panel__(self):
        return self._layout

CounterButton(width=300)

I get

TypeError: PyComponent._sync__views() takes 1 positional argument but 2 were given

Do you plan on finalizing the implementation of the PyComponent @philippjfr ? What would the next step be?

panel/custom.py Outdated Show resolved Hide resolved
@philippjfr
Copy link
Member

It seems to me that the PyComponent is in a very preliminary state?

I don't plan on changing anything else, there was just a small typo. I'm unclear whether it's useful or adds anything on top of what Viewer does.

panel/custom.py Outdated Show resolved Hide resolved
@philippjfr
Copy link
Member

Nevermind, it does need a lot more work.

@philippjfr
Copy link
Member

The docs can still be improved here but the component now behaves as I'd like it to and I want it to get into an RC release.

@philippjfr philippjfr merged commit 43b8b18 into main Sep 3, 2024
15 of 16 checks passed
@philippjfr philippjfr deleted the enhancement/document-composite-widget branch September 3, 2024 09:37
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.

3 participants