Skip to content

Commit

Permalink
Very rough ideas for next steps
Browse files Browse the repository at this point in the history
  • Loading branch information
antonymilne committed Nov 3, 2023
1 parent a2950cd commit d6c2215
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
16 changes: 16 additions & 0 deletions vizro-core/examples/default/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Example to show dashboard configuration."""
import os
import pandas as pd

import vizro.models as vm
import vizro.plotly.express as px
Expand Down Expand Up @@ -146,3 +147,18 @@ def empty_cache(empty_button_id_n_clicks):
# processes=3,
# dev_tools_hot_reload=False
# )

# Options for configuring per-dataset arguments:
# 1.
data_manager["iris"] = lambda: pd.DataFrame()
data_manager["iris"].set_cache(timeout=50)


# 2.
class VizroDataSet:
pass


data_manager["iris"] = VizroDataSet(lambda: pd.DataFrame(), timeout=50)

# 3.
14 changes: 11 additions & 3 deletions vizro-core/src/vizro/managers/_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DataManager:
"""

_cache = Cache(config={"CACHE_TYPE": "NullCache"})
_cache = Cache(config={"CACHE_TYPE": "SimpleCache"})

def __init__(self):
self.__lazy_data: Dict[DatasetName, pd_LazyDataFrame] = {}
Expand Down Expand Up @@ -68,12 +68,20 @@ def _add_component(self, component_id: ComponentID, dataset_name: DatasetName):
)
self.__component_to_original[component_id] = dataset_name

@_cache.memoize()
def _load_lazy_data(self, dataset_name: DatasetName) -> pd.DataFrame:
self._cache_dataset_arguments = {"iris": {"timeout": 50}, "other_dataset": {"timeout": 100}}

@self._cache.memoize(**self._cache_dataset_arguments.get(dataset_name, {}))
# timeout (including 0 -> never expires), unless -> always executes function (like
# timeout=0.000001) and doesn't update cache.
# timeout and unless need to depend on dataset_name
def inner():
self.__lazy_data[dataset_name]()

"""Returns the original data for `dataset_name`."""
logger.debug("reloading lazy data: %s", dataset_name)
time.sleep(2.0)
return self.__lazy_data[dataset_name]()
return inner()

def _get_component_data(self, component_id: ComponentID) -> pd.DataFrame:
"""Returns the original data for `component_id`."""
Expand Down

0 comments on commit d6c2215

Please sign in to comment.