ui.refreshable function behaving unexpectedly #2921
-
QuestionI'm trying to run this section of code to auto generate color based reinforcement for a client when they are selecting choices, but when i run this i get an error message so long that VS code doesn't even render the full response. In theory, this doesn't seem to far off of the example provided in the site documentation, but there is additional logic in the if statement at the bottom. Any help would be appreciated. This is just an excerpt taken from the total page, but extracted to a separate page, it provides the same errors. I've also modified it to run with the "on_change" property of checkbox and it yields the same results. from nicegui import ui
@ui.refreshable
def color_change():
color_, set_color_ = ui.state('red')
count_, set_count_ = ui.state([0,0,0,0,0])
ui.checkbox(value=bool(count_[0]), on_change=lambda e: set_count_(count_[0] + 1) if e.value else set_count_(count_[0]-1)).props(f'label="Property 1" color={color_}')
ui.checkbox(value=bool(count_[1]), on_change=lambda e: set_count_(count_[1] + 1) if e.value else set_count_(count_[1]-1)).props(f'label="Property 2" color={color_}')
ui.checkbox(value=bool(count_[2]), on_change=lambda e: set_count_(count_[2] + 1) if e.value else set_count_(count_[2]-1)).props(f'label="Property 3" color={color_}')
ui.checkbox(value=bool(count_[3]), on_change=lambda e: set_count_(count_[3] + 1) if e.value else set_count_(count_[3]-1)).props(f'label="Property 4" color={color_}')
ui.checkbox(value=bool(count_[4]), on_change=lambda e: set_count_(count_[4] + 1) if e.value else set_count_(count_[4]-1)).props(f'label="Property 5" color={color_}')
if sum(count_) == 5:
set_color_("green")
ui.icon("done", color="green").classes('text-5xl')
else:
set_color_("red")
ui.icon("done", color="red").classes('text-5xl')
color_change()
ui.run(host="127.0.0.1") @falkoschindler updated |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @vickorian, When calling But I guess nicegui/nicegui/functions/refreshable.py Lines 156 to 158 in 97d4027 |
Beta Was this translation helpful? Give feedback.
I just created PR #2922 to add the early exit.