any_variable
GET_VALUE_OVERRIDE
Optional context variable which can be used to override the default behaviour of get_current_value()
.
get_current_value
async def get_current_value(variable: dict,
timeout: float = 3,
raw: bool = False) -> Any
Retrieve the current value of the variable for the current user
Only works in a context where Dara can infer the user to get the value for:
- inside variable/action/py_component handlers
- anywhere when using single-user basic auth config, assumes we're asking for the current value for that single user
Arguments:
variable
: dict representation of the variabletimeout
: time to wait for a value before raising a TimeoutErrorraw
: whether to return the raw result
AnyVariable
from dara.core.interactivity.any_variable import AnyVariable
class AnyVariable(BaseModel, abc.ABC)
Base class for all variables. Used for typing to specify that any variable can be provided.
Attributes
- uid: str
Methods
reset
def reset()
Create an action to reset the value of this Variable to it's default value.
For derived variables this will trigger the function to be re-run.
from dara.core import Variable
from dara.components import Button
counter = Variable(default=0)
Button(
'Reset',
onclick=counter.reset(),
)
get_current_value
async def get_current_value(timeout: float = 3) -> Any
Retrieve the current value of the variable for the current user
Only works in a context where Dara can infer the user to get the value for:
- inside variable/action/py_component handlers
- anywhere when using single-user basic auth config, assumes we're asking for the current value for that single user
Arguments:
timeout
: time to wait for a value before raising a TimeoutError