Skip to main content

data_variable

DataVariable

from dara.core.interactivity.data_variable import DataVariable

class DataVariable(AnyDataVariable)

DataVariable represents a variable that is specifically designed to hold datasets.

Example use cases:

Global data provided upfront

global_data = DataVariable(data=DataFrame({'a': [1, 2, 3]})) # implicit cache='global'

User-specific data, cannot be provided upfront (top-level code does not have a user context)

user_data = DataVariable(cache='user')
UploadDropzone(target=user_data)

Session-specific data, cannot be provided upfront (top-level code does not have a session context)

session_data = DataVariable(cache='session')
UpdateVariable(func=some_data_transformation, variable=session_data)

Attributes

  • uid: str
  • filters: Optional[FilterQuery]
  • cache: Optional[BaseCachePolicy]

Methods

__init__

def __init__(data: Optional[DataFrame] = None,
cache: CacheArgType = Cache.Type.GLOBAL,
uid: Optional[str] = None,
**kwargs) -> None

DataVariable represents a variable that is specifically designed to hold datasets.

Arguments:

  • data: optional dataframe
  • uid: the unique identifier for this variable; if not provided a random one is generated
  • filters: a dictionary of filters to apply to the data
  • cache: how to cache the result; 'user' per user, 'session' per session, 'global' for all users

update_value

@classmethod
def update_value(cls, var_entry: DataVariableRegistryEntry, store: CacheStore,
data: Optional[DataFrame])

Update the data entry and notify all clients about the update.

Arguments:

  • var_entry: the entry in the registry
  • data: the data to update
  • store: store instance

get_value

@classmethod
async def get_value(cls,
var_entry: DataVariableRegistryEntry,
store: CacheStore,
filters: Optional[Union[FilterQuery, dict]] = None,
pagination: Optional[Pagination] = None,
format_for_display: bool = False) -> Optional[DataFrame]

Get the value of this DataVariable.

get_total_count

@classmethod
async def get_total_count(cls, var_entry: DataVariableRegistryEntry,
store: CacheStore, filters: Optional[FilterQuery])

Get total count of the data variable.

Arguments:

  • var_entry: variable entry
  • store: store
  • filters: filters to get count for

get_schema

@classmethod
async def get_schema(cls, var_entry: DataVariableRegistryEntry,
store: CacheStore)

Get the schema of the data variable.

Arguments:

  • var_entry: variable entry
  • store: store

update

def update(value: Optional[DataFrame])

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

import pandas as pd
from dara.core import DataVariable
from dara.components import Button

data = DataVariable(pd.DataFrame({'a': [1, 2, 3]}))

Button(
'Empty Data',
onclick=data.update(None),
)

DataStoreEntry

from dara.core.interactivity.data_variable import DataStoreEntry

class DataStoreEntry(BaseModel)

Entry in the cache store for a DataVariable. Can either be a DataFrame or a path to a file on disk.

Attributes

  • data: Optional[DataFrame]
  • path: Optional[str]