-
Notifications
You must be signed in to change notification settings - Fork 2
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 support for custom tabulator options #126
Conversation
CodSpeed Performance ReportMerging #126 will not alter performanceComparing Summary
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #126 +/- ##
=======================================
Coverage 86.33% 86.34%
=======================================
Files 26 26
Lines 2774 2775 +1
=======================================
+ Hits 2395 2396 +1
Misses 379 379 ☔ View full report in Codecov by Sentry. |
holonote/app/tabulator.py
Outdated
@@ -61,6 +64,7 @@ def new_style(row): | |||
buttons={"delete": '<i class="fa fa-trash"></i>'}, | |||
show_index=False, | |||
selectable=True, | |||
**self.tabulator_kwargs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a param
should this be wrapped in a function decorated with pn.depends('tabulator_kwargs')
, running self.tabulator.param.update(**tabulator_kwargs)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing not, since tabulator_kwargs
(and _create_tabulator) are intended to only be used once. But it's a good question for someone with a greater understanding to jump in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the tabulator_kwargs
should be synced with the Tabulator
. There actually is an API on Reactive
objects to do this, specifically, could you try:
**self.tabulator_kwargs, | |
refs=self.param.tabulator_kwargs |
This will update keep the tabulator_kwargs
dictionary synced with the Tabulator
parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my understanding (which I just pushed changes for) is that it is appropriate to make tabulator_kwargs
into a param (I'm guessing now requiring allow_refs=True
?), and that it will be synced solely by using the refs=
API, without the dependence on the depends
decorator.
Just curious, what is the reasoning that tabulator_kwargs
should remain synced with Tabulator beyond initialization? Is it just the general design inclination to allow for future flexibility in case some property about the Tabulator will be internally modified?
Also, am I correct in assuming the allow_refs=True
is now required or am I confusing concepts?
Thanks for the guidance!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, if my recent changes look good, please approve and merge! thank you
Note to self, I was thinking about adding input validation warnings for dict items like this: class _TabulatorOpts(param.Dict):
def __init__(self, default={}, doc="kwargs to pass to tabulator", allow_refs=True):
super().__init__(default=default, doc=doc, allow_refs=allow_refs)
def _validate(self, val) -> None:
super()._validate(val)
warn_opts = ("show_index", "selectable", "buttons")
for k in val:
if k in warn_opts:
warn(f"`{k}` is set directly and should not be passed through `tabulator_opts`") But then the doc entry doesn't appear in the docstring, so I think I'll leave it out and just let the validation be a side effect of passing in a duplicate kwarg of one that is set directly |
You could create your own param type with validation, e.g.
As an example, Panel does it for a few like Margin. |
I think that's pretty much what I proposed in the comment above, no? I think I'll avoid for now because I prefer the docs to show up, but thanks. How does this PR look currently? |
I think the PR looks fine; I'm just not sure if
Oops yeah, I didn't recognize it since I'm used to seeing inheriting from
I'm a bit confused about this one. from param import Parameter, Parameterized
class Aspect(Parameter):
"""
A Parameter type to validate aspect ratios. Supports numeric values
and auto.
"""
def __init__(self, default=None, allow_None=True, **params):
super().__init__(default=default, allow_None=allow_None, **params)
self._validate(default)
def _validate(self, val):
self._validate_value(val, self.allow_None)
def _validate_value(self, val, allow_None):
...
class Test(Parameterized):
tabulator_aspect = Aspect(doc="Just testing")
Test? results in
|
There's no reason not to enable allow_refs but it isn't strictly needed. Tabulator allows refs so that's all that's necessary, enabling it here would make it possible to bind references to these objects which is also nice. |
@@ -14,6 +14,7 @@ class AnnotatorTable(pn.viewable.Viewer): | |||
annotator = param.Parameter(allow_refs=False) | |||
tabulator = param.Parameter(allow_refs=False) | |||
dataframe = param.DataFrame() | |||
tabulator_kwargs = param.Dict(default={}, doc="kwargs to pass to tabulator", allow_refs=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do something like this to validate the values:
@param.depends('tabulator_kwargs')
def _validated_tabulator_kwargs(self):
...
return self.tabulator_kwargs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this as is but if you want to validate the kwargs I'd be happy with that too.
Fixes #125
Use
tabulator_kwargs
and refer to the options https://panel.holoviz.org/reference/widgets/Tabulator.htmlTODO:
allow for(another PR)show_indices
to be overwrittenFor instance:
Code