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

Add throttled argument to pn.param widgets parameter #1800

Merged
merged 6 commits into from
Dec 10, 2020
Merged

Add throttled argument to pn.param widgets parameter #1800

merged 6 commits into from
Dec 10, 2020

Conversation

hoxbro
Copy link
Member

@hoxbro hoxbro commented Nov 22, 2020

The reason for this PR it is hard to incorporate value_throttled for sliders into a parametrized class.
This will add the possibility to add a throttled argument to pn.param widgets argument. So the following is possible:

import param
import panel as pn


class A(param.Parameterized):
    value_ = param.Range(
        default=(100, 250),
        bounds=(0, 250),
    )
    
    value_throttled_ = param.Range(
        default=(100, 250),
        bounds=(0, 250),
    )
  
    def __init__(self, **params):
        super().__init__(**params)
        widgets = {
            "value_": pn.widgets.IntRangeSlider,
            "value_throttled_": {
                "type": pn.widgets.IntRangeSlider,
                "throttled": True
            },
        }
        self.controls = pn.Param(self, widgets=widgets)

    @param.depends("controls")
    def calculation(self):
        return self.value_, self.value_throttled_


a = A()
pn.Column(a.controls, a.calculation)

screen

To get this to work I'm changing the param object from linking with value to linking with value_throttled of the slider and vice versa. This is only done if throttled is enabled and the widget contains the attribute value_throttled.

This is the reason why the unit test without throttled enabled is on value and with throttled enabled is on value_throttled.

I hope that the configuration of throttled is done as mentioned here.

If there is a better way to implement this, this PR can be closed.

TODO:

  • I need some guidance if I need to add more to the unit test.
  • Add some documentation for this feature. I think it properly should be located here.

@codecov
Copy link

codecov bot commented Nov 22, 2020

Codecov Report

Merging #1800 (43d4cf2) into master (d67c09d) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1800      +/-   ##
==========================================
+ Coverage   85.13%   85.15%   +0.02%     
==========================================
  Files         151      151              
  Lines       17954    17988      +34     
==========================================
+ Hits        15285    15318      +33     
- Misses       2669     2670       +1     
Impacted Files Coverage Δ
panel/param.py 90.30% <100.00%> (+0.08%) ⬆️
panel/tests/test_param.py 99.87% <100.00%> (+<0.01%) ⬆️
panel/pane/holoviews.py 83.88% <0.00%> (-0.17%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d67c09d...43d4cf2. Read the comment docs.

@hoxbro hoxbro changed the title [WIP] Add throttled argument to pn.param widgets parameter Add throttled argument to pn.param widgets parameter Dec 6, 2020
@philippjfr
Copy link
Member

This looks fabulous, thanks for your efforts around this!

@philippjfr philippjfr merged commit f01a739 into holoviz:master Dec 10, 2020
@hoxbro hoxbro deleted the throttled_param branch December 10, 2020 18:25
philippjfr pushed a commit that referenced this pull request Jan 18, 2021
* Adding throttled to param

* Moved throttled to widgets argument

* Added value_throttled to updates

* Added unittest

* More clear seperation if widget is throttled or not

* Added documentation
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.

None yet

2 participants