diff --git a/shinyecharts/_core.py b/shinyecharts/_core.py index 283bbdf..5035577 100644 --- a/shinyecharts/_core.py +++ b/shinyecharts/_core.py @@ -13,7 +13,8 @@ def snake_to_camel_case(snake_str: str) -> str: def df_to_dataset(df: DataFrame = None) -> dict: - return {"dataset": {"source": [df.columns.to_list()] + df.to_numpy().tolist()}} + return dict(dataset=dict(source=df.to_dict(orient="list"))) + # return {"dataset": {"source": [df.columns.to_list()] + df.to_numpy().tolist()}} def df_to_pie_data(df: DataFrame, name: str, value: str) -> list: diff --git a/shinyecharts/chart.py b/shinyecharts/chart.py index 899fa76..fc1d7c8 100644 --- a/shinyecharts/chart.py +++ b/shinyecharts/chart.py @@ -40,11 +40,16 @@ def get_options(self) -> dict: # Set option attributes def attr(self, **kwargs) -> Chart: - pass + self._option.update(**kwargs) + return self # TODO: Set data here def set_data(self, data: DataFrame | dict) -> Chart: - pass + # self._data = ( + # df_to_dataset(self._data) if isinstance(self._data, DataFrame) else dict() + # ) + self._data = data + return self def set_option(self, option: dict | ChartOption | BaseOption) -> Chart: self._option = option if isinstance(option, dict) else option.to_dict() diff --git a/shinyecharts/express.py b/shinyecharts/express.py index e4aee7e..85c52a8 100644 --- a/shinyecharts/express.py +++ b/shinyecharts/express.py @@ -43,6 +43,7 @@ def x_axis(self, type: str = "value", **kwargs) -> Chart: def y_axis(self): return self + # TODO: Rename to series_options!? But which method will then add the series? def series(self, type: SeriesType | str, **kwargs) -> Chart: type = SeriesType(type).value if type == "bar":