Skip to main content

url_variable

UrlVariable

from dara.core.interactivity.url_variable import UrlVariable

class UrlVariable(NonDataVariable, Generic[VariableType])

A UrlVariable is very similar to a normal Variable however rather than it's state being stored in the memory of the client it's value is stored in the url of page as a query parameter. This is very useful for parameterizing pages as you switch from one to the other.

Attributes

  • default: Optional[VariableType]
  • query: str
  • uid: str

Methods

__init__

def __init__(query: str,
default: Optional[VariableType] = None,
uid: Optional[str] = None)

A UrlVariable is very similar to a normal Variable however rather than it's state being stored in the memory of

the client it's value is stored in the url of page as a query parameter. This is very useful for parameterizing pages as you switch from one to the other.

Arguments:

  • query: the key in the query string to identify this variable
  • default: the initial value for the variable, defaults to None
  • uid: the unique identifier for this variable; if not provided a random one is generated

sync

def sync()

Create an action to synchronise the value of this UrlVariable with input value sent from the component.


from dara.core import UrlVariable
from dara.components import Select

var = UrlVariable('first', query='num')
another_var = UrlVariable('second', query='num_two')

Select(
value=var,
items=['first', 'second', 'third'],
onchange=another_var.sync(),
)

toggle

def toggle()

Create an action to toggle the value of this UrlVariable. Note this only works for boolean variables.


from dara.core import UrlVariable
from dara.components import Button

var = UrlVariable(True, query='show')

Button(
'Toggle',
onclick=var.toggle(),
)

update

def update(value: Any)

Create an action to update the value of this UrlVariable to a provided value.


from dara.core import UrlVariable
from dara.components import Button

show = UrlVariable(True, query='show')

Button(
'Hide',
onclick=show.update(False),
)