-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[🐛 BUG] Multi-value slider with lov binds value
to the post-adapter lov elements
#2290
Comments
Does it work for single value selection ? |
If you want an id different from your label, you need to specify it in your adapter: def aggregation_adapter(aggregation):
return (aggregation, aggregation.title()) Does that work for you @arcanaxion ? import taipy.gui.builder as tgb
from taipy.gui import Gui
aggregation_list = ["minute", "hour", "day", "week"]
selected_aggregation = [aggregation_list[0], aggregation_list[1]]
def aggregation_adapter(aggregation):
return (aggregation, aggregation.title())
with tgb.Page() as page:
tgb.text("# Adapter modifying bound value for multi-value slider", mode="md")
tgb.slider("{selected_aggregation}", lov="{aggregation_list}", label="Aggregation", adapter=aggregation_adapter)
tgb.text("{selected_aggregation}")
def on_change(state, var_name, var_value):
print(var_name, type(var_value), var_value)
if __name__ == "__main__":
gui = Gui(page=page)
gui.run(title="2290 [🐛 BUG] Multi-value slider with lov binds value to the post-adapter lov elements") |
@FredLL-Avaiga Yes, your correction works for me and it makes sense. Indeed the docs state that adapter should return a tuple. But the inconsistency using my (wrong) method only seems to be affecting multi-value sliders: from taipy.gui import Gui
import taipy.gui.builder as tgb
aggregation_list = ["minute", "hour", "day", "week"]
selected_aggregation_multiple = [aggregation_list[0], aggregation_list[1]]
selected_aggregation = aggregation_list[0]
selected_aggregation_selector = aggregation_list[0]
def aggregation_adapter(aggregation):
return aggregation.title()
with tgb.Page() as page:
tgb.text("# Adapter modifying bound value for multi-value slider", mode="md")
tgb.slider("{selected_aggregation_multiple}", lov="{aggregation_list}", adapter=aggregation_adapter)
tgb.text("{selected_aggregation_multiple}")
tgb.slider("{selected_aggregation}", lov="{aggregation_list}", adapter=aggregation_adapter)
tgb.text("{selected_aggregation}")
tgb.selector("{selected_aggregation_selector}", lov="{aggregation_list}", adapter=aggregation_adapter)
tgb.text("{selected_aggregation_selector}")
def on_change(state, var_name, var_value):
print(var_name, type(var_value), var_value)
if __name__ == "__main__":
gui = Gui(page=page)
gui.run() Probably this should either work consistently, or perhaps raise an error if the adapter is not returning a 2-element tuple. |
@FabienLelaquais Doc ? |
@FredLL-Avaiga I think the issue I'm having is unrelated to adapters. I'm comparing 3 versions:
Problem with treeFirst I noticed that the "tree" element was returning ids instead of lov elements. Example copied from the docs: from taipy.gui import Gui, State, Markdown
from typing import Any
users = [
{"id": "231", "label": "Johanna", "year": 1987, "children": [{"id": "231.1", "label": "Johanna's son", "year": 2006}]},
{"id": "125", "label": "John", "year": 1979, "children": []},
{"id": "4", "label": "Peter", "year": 1968, "children": []},
{"id": "31", "label": "Mary", "year": 1974, "children": []}
]
user_sel = users[2]
page = Markdown(
"""
# Trees
<|{user_sel}|tree|lov={users}|>
""")
def on_change(state: State, var_name: str, var_value: Any):
print(var_name, type(var_value), var_value)
if __name__ == "__main__":
gui = Gui(page=page)
gui.run(run_browser=False) When I click on John: Setting This made me look at the example in this github issue again. Slider, without adapterSee the following. I'm not using tgb because the tgb.selector didn't seem to work for me in 3.0.1: from taipy.gui import Gui
import taipy.gui.builder as tgb
aggregation_list = [("minute", "Minute"), ("hour", "Hour"), ("day", "Day"), ("week", "Week")]
selected_aggregation_slider_multiple = [aggregation_list[0], aggregation_list[1]]
selected_aggregation_slider_single = None
selected_aggregation_selector_single = aggregation_list[0]
page = Markdown(
"""
# No adapter
<|{selected_aggregation_slider_multiple}|slider|lov={aggregation_list}|>
<|{repr(selected_aggregation_slider_multiple)}|>
<|{selected_aggregation_slider_single}|slider|lov={aggregation_list}|>
<|{repr(selected_aggregation_slider_single)}|>
<|{selected_aggregation_selector_single}|selector|lov={aggregation_list}|>
<|{repr(selected_aggregation_selector_single)}|>
""")
def on_change(state, var_name, var_value):
print(var_name, type(var_value), var_value)
if __name__ == "__main__":
gui = Gui(page=page)
gui.run(run_browser=False, use_reloader=True) 3.0.1This has the most expected behaviour to me: 3.0.1.slider.mp4All 3 visual elements are giving the selected lov element (a tuple) as its value. 4.0.1Here, a possibly unrelated issue, the single value slider becomes strange: 4.0.1.slider.mp4I'm expecting a single value slider but it's becoming a multi-value slider. developHere we start seeing what I think this github issue is related to: develop.slider.mp4The multi-value has renders the expected initial state. After interaction, the multi-value slider starts giving ids instead of lov elements, even though The unexpected behaviour for single value slider is also still present. For all 3 versions, the selector has the same expected behaviour. If this is actually just yet-to-be-documented behaviour for a future release, please let me know and I will go back to stable 😅 |
I'll look into it |
There was indeed a bug in the way we handle multiple selection in lov based components |
What went wrong? 🤔
Example code:
In develop, modifying the slider displays:
Seems to be a regression -- was working as expected in 4.0.1.
Expected Behavior
Values should be lowercase
Browsers
Chrome, Firefox
OS
Windows, Linux
Version of Taipy
develop
Acceptance Criteria
Code of Conduct
The text was updated successfully, but these errors were encountered: