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

Make editable sliders name parameter editable (from python) #2663

Closed
TheoMathurin opened this issue Aug 25, 2021 · 7 comments · Fixed by #2678
Closed

Make editable sliders name parameter editable (from python) #2663

TheoMathurin opened this issue Aug 25, 2021 · 7 comments · Fixed by #2678

Comments

@TheoMathurin
Copy link
Contributor

Editable sliders are a very nice addition to panel components and can advantageously replace conventional sliders in most cases in my opinion. However there is a difference currently with respect to the name parameter, which is constant in editable sliders while it is not in conventional sliders.

As in my app I use sliders which have their name changed programmatically, I would like to know if editable sliders could be modified so that the name parameter is no longer constant? In general I think it's best to make editable sliders behave identically to their non-editable counterparts as far as practicable.

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Aug 25, 2021

Hi @TheoMathurin. Could you provide a small, reproducible code example? That would make it easier to reproduce, explore, fix and release. Thanks.

And for me to probably show you a temporary workaround :-)

@TheoMathurin
Copy link
Contributor Author

TheoMathurin commented Aug 25, 2021

Hi @MarcSkovMadsen

Sure

import panel.widgets as pnw

slider = pnw.EditableFloatSlider(name='name1')
slider.param.set_param(name='name2')

Thanks in advance

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Aug 25, 2021

I tried to find a workaround but it errors

import param
import panel.widgets as pnw
import panel as pn

pn.extension()

slider = pnw.EditableFloatSlider(name='name1')

with param.edit_constant(slider):
    slider.name='name3'

slider
TypeError: Constant parameter 'name' cannot be modified

@TheoMathurin
Copy link
Contributor Author

That is the same error you get when trying to modify it directly.

@xavArtley
Copy link
Collaborator

The work around is :
slider._label.param.set_param(**{'margin': (0,10,0,0), 'value': "name3"})

@TheoMathurin
Copy link
Contributor Author

It works, thanks @xavArtley!

@maximlt
Copy link
Member

maximlt commented Aug 25, 2021

try:
    slider.name =  "name3"
except TypeError:
    pass

also works. This is because the name of the widget is actually being correctly set in the first place (under the hood the value of a StaticText widget is set). However, the code currently sets the name of the Column param that wraps the StaticText and the slider. The name of any param can be set but not edited, which is what raises the error.

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 a pull request may close this issue.

4 participants