Skip to content

Commit

Permalink
Remove callable_component and add figure to table
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschulz-COL committed Oct 23, 2023
1 parent 60f3963 commit fa055a5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions vizro-core/examples/default/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def AgGrid(data_frame=None):
title="Color manager",
path="color-manager",
components=[
vm.Table(id="table2", table=dash_data_table(data_frame=data, style_header={"border": "1px solid green"})),
vm.Table(id="table2", figure=dash_data_table(data_frame=data, style_header={"border": "1px solid green"})),
vm.Graph(
id="graph",
figure=px.scatter(
Expand All @@ -78,7 +78,7 @@ def AgGrid(data_frame=None):
id="hist",
figure=px.histogram(data_frame=px.data.iris(), x="sepal_width", y="sepal_length", color="species"),
),
vm.Table(id="grid", table=AgGrid(data_frame="table_data")),
vm.Table(id="grid", figure=AgGrid(data_frame="table_data")),
],
controls=[
vm.Filter(column="State", selector=vm.Dropdown()),
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/actions/_actions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _get_parametrized_config(
# TODO - avoid calling _captured_callable. Once we have done this we can remove _arguments from
# CapturedCallable entirely.
graph_config = deepcopy(
getattr(model_manager[target], model_manager[target]._callable_component)._arguments # type: ignore[attr-defined]
model_manager[target].figure._arguments # type: ignore[attr-defined]
)
if "data_frame" in graph_config:
graph_config.pop("data_frame")
Expand Down
1 change: 0 additions & 1 deletion vizro-core/src/vizro/models/_components/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Graph(VizroBaseModel):

# Component properties for actions and interactions
_output_property: str = PrivateAttr("figure")
_callable_component: str = PrivateAttr("figure")

# Re-used validators
_set_actions = _action_validator_factory("clickData")
Expand Down
7 changes: 3 additions & 4 deletions vizro-core/src/vizro/models/_components/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ class Table(VizroBaseModel):
Args:
type (Literal["table"]): Defaults to `"table"`.
table (CapturedCallable): Table like object to be displayed. Current choices include:
figure (CapturedCallable): Table like object to be displayed. Current choices include:
[`dash_table.DataTable`](https://dash.plotly.com/datatable).
actions (List[Action]): See [`Action`][vizro.models.Action]. Defaults to `[]`.
"""

type: Literal["table"] = "table"
table: CapturedCallable = Field(..., import_path = vt, description="Table to be visualized on dashboard")
figure: CapturedCallable = Field(..., import_path = vt, description="Table to be visualized on dashboard")
actions: List[Action] = []

# Component properties for actions and interactions
_output_property: str = PrivateAttr("children")
_callable_component: str = PrivateAttr("table")

# validator
set_actions = _action_validator_factory("active_cell") # type: ignore[pydantic-field]
_validate_callable = validator("table", allow_reuse=True, always=True)(_process_callable_data_frame)
_validate_callable = validator("figure", allow_reuse=True, always=True)(_process_callable_data_frame)

# Convenience wrapper/syntactic sugar.
def __call__(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, **data):
@_log_call
def pre_build(self):
# TODO: Remove default on page load action if possible
if any(hasattr(component, "_callable_component") for component in self.components):
if any(hasattr(component, "figure") for component in self.components):
self.actions = [
ActionsChain(
id=f"{ON_PAGE_LOAD_ACTION_PREFIX}_{self.id}",
Expand Down

0 comments on commit fa055a5

Please sign in to comment.