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

discreteslider crashes with only a single value #2395

Closed
andhuang-CLGX opened this issue Jun 15, 2021 · 5 comments · Fixed by #3297
Closed

discreteslider crashes with only a single value #2395

andhuang-CLGX opened this issue Jun 15, 2021 · 5 comments · Fixed by #3297

Comments

@andhuang-CLGX
Copy link

pn.widgets.DiscreteSlider(options=["something"])
@andhuang-CLGX
Copy link
Author

Well I guess all sliders are like this, but maybe it'd be good to duplicate the first value or disable it if only one value?

@MarcSkovMadsen
Copy link
Collaborator

A minimum reproducible example would be

import panel as pn
pn.extension(sizing_mode="stretch_width")

pn.widgets.DiscreteSlider(options=["something else"]).servable()
ValueError: Slider 'start' and 'end' cannot be equal.
Traceback (most recent call last):
  File "c:\repos\private\panel_docker\panel\.venv\lib\site-packages\bokeh\application\handlers\code_runner.py", line 197, in run
    exec(self._code, module.__dict__)
  File "C:\repos\private\panel_docker\panel\panel\test_example.py", line 4, in <module>
    pn.widgets.DiscreteSlider(options=["something else"]).servable()
  File "c:\repos\private\panel_docker\panel\panel\viewable.py", line 331, in servable
    self.server_doc(title=title, location=location)
  File "c:\repos\private\panel_docker\panel\panel\viewable.py", line 782, in server_doc
    model = self.get_root(doc)
  File "c:\repos\private\panel_docker\panel\panel\viewable.py", line 500, in get_root
    root = self._get_model(doc, comm=comm)
  File "c:\repos\private\panel_docker\panel\panel\widgets\base.py", line 173, in _get_model
    model = self._composite._get_model(doc, root, parent, comm)
  File "c:\repos\private\panel_docker\panel\panel\layout\base.py", line 113, in _get_model
    objects = self._get_objects(model, [], doc, root, comm)
  File "c:\repos\private\panel_docker\panel\panel\layout\base.py", line 103, in _get_objects
    child = pane._get_model(doc, root, model, comm)
  File "c:\repos\private\panel_docker\panel\panel\widgets\base.py", line 79, in _get_model
    model = self._widget_type(**self._process_param_change(self._init_params()))
  File "c:\repos\private\panel_docker\panel\.venv\lib\site-packages\bokeh\models\widgets\sliders.py", line 71, in __init__
    raise ValueError("Slider 'start' and 'end' cannot be equal.")
ValueError: Slider 'start' and 'end' cannot be equal.

@MarcSkovMadsen
Copy link
Collaborator

Hi @andhuang-CLGX

  • Could you describe the use case for a discreteslider with only one option?
  • And how you would like this to look?

@ahuang11
Copy link
Contributor

I imagine:

import panel as pn
pn.extension(sizing_mode="stretch_width")

pn.widgets.DiscreteSlider(options=["something else"] * 2).servable()

The reason for this is if the options are dynamically generated and there is only one selectable option, it would crash the program.

@philippjfr philippjfr modified the milestones: no milestone, v0.12.x Jun 29, 2021
@philippjfr philippjfr modified the milestones: v0.12.x, v0.13.0 Jan 3, 2022
@philippjfr
Copy link
Member

Agree that this is an issue, widgets can frequently be auto-generated so while it makes little sense to have a single valued slider (or any widget for that matter) it shouldn't error. The real problem we face here is that bokeh does not like it. Duplicating the option is a fix, not sure it is the cleanest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants