Changing default widget types in pn.param()

I’m wondering if there is a way to say

for all param.Integer(), set the widget to be a box instead of a slider

I know that I can set individual params via pn.Param.widgets but is there a way to do this in bulk by setting a type of param to display a certain way?

I’m pretty sure you can do it with passing in a dict to pn.Param(widgets={})

Do you mean defaults?

Potentially pn.Param.mapping.update()

ah yes, potentially - it’s the mapping update ability to set the widget for an entire class of parameter that i’m looking for!

How does one use the mapping keyword in a param object? This is what I’m trying to achieve, below:

widget = pn.Param(
                    self.param,
                    display_threshold = 0,
                    show_name = False,
                    sort = self.sort_by_precedence,
                    widgets = {},
                    expand=False,
                    expand_button = True,
                    expand_layout = pn.layout.base.Row,
                    mapping = {"param.Integer" : "LiteralInputTyped"}
            )

but mapping = {"param.Integer" : "LiteralInputTyped"} throws an error, got an unexpected keyword argument 'mapping'

thanks!

You set it before instantiating I think.
pn.Param.mapping.update() or if you want to override all defaults pn.Param.mapping = {}

confused as to how to do this… pn.Param.mapping is apparently a dictionary of <class 'param.parameters.<parameter>'> - Integer, Float, etc., what would be the command in order to edit these as they’re seemingly dictionary keys that aren’t strings?

Dictionary keys don’t have to be strings as long as they’re immutable, e.g. {("a", "b"): "a, b"} is valid since tuples are immutable. Just import param and use it like strings.

Oh you mean you usually do this, but it’s invalid here:

pn.Param.mapping.update(int=pn.widgets.IntSpinner)

Just use an actual dictionary:

pn.Param.mapping.update({param.Integer: pn.widgets.IntSpinner})
1 Like