param.reactive.reactive_ops.where#
- reactive_ops.where(x, y) rx[source]#
Return either
xorydepending on the current state of the expression.This method implements a reactive version of a ternary conditional expression. It evaluates the current reactive expression as a condition and returns
xif the condition isTrue, oryif the condition isFalse.- Parameters:
- Returns:
A reactive expression that evaluates to
xorybased on the current state of the condition.- Return type:
Examples
Use
.whereto implement a reactive conditional:>>> import param >>> rx_value = param.rx(True) >>> rx_result = rx_value.rx.where("Condition is True", "Condition is False")
Check the result when the condition is
True:>>> rx_result.rx.value 'Condition is True'
Change the reactive condition and observe the updated result:
>>> rx_value.rx.value = False >>> rx_result.rx.value 'Condition is False'
Combine
.wherewith reactive expressions for dynamic updates:>>> rx_num = param.rx(10) >>> rx_condition = rx_num > 5 >>> rx_result = rx_condition.rx.where("Above 5", "5 or below") >>> rx_result.rx.value 'Above 5'
Update the reactive value and see the conditional result change:
>>> rx_num.rx.value = 3 >>> rx_result.rx.value '5 or below'