From 69b745c4ccb289d8d6cb8359148ec05ca3e67e1c Mon Sep 17 00:00:00 2001 From: Stefan Kuethe Date: Tue, 20 Feb 2024 11:38:30 +0100 Subject: [PATCH] Add example --- docs/examples/playground/app2.py | 20 ++++++++++++++++++++ shinyecharts/express.py | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 docs/examples/playground/app2.py diff --git a/docs/examples/playground/app2.py b/docs/examples/playground/app2.py new file mode 100644 index 0000000..f0776c3 --- /dev/null +++ b/docs/examples/playground/app2.py @@ -0,0 +1,20 @@ +from pandas import DataFrame +from shiny.express import ui +from shinyecharts.express import Chart, InitOptions, SeriesType +from shinyecharts.renderer import ChartRenderer + +init_options = InitOptions(width=600, height=400, renderer="canvas") + +data = DataFrame(dict(a=[1, 2, 3, 4], b=[2, 4, 8, 4], c=[3, -2, 3, 1])) + +pie_data = DataFrame(dict(name=["A", "B", "C"], value=[10, 70, 40])) + + +@ChartRenderer +def render_line_chart(): + return Chart().data(data).encode("a", "b").encode("a", "c", color="pink") + + +@ChartRenderer +def render_pie_chart(): + return Chart().data(pie_data).series("pie") diff --git a/shinyecharts/express.py b/shinyecharts/express.py index 85c52a8..f10682a 100644 --- a/shinyecharts/express.py +++ b/shinyecharts/express.py @@ -15,6 +15,7 @@ def __init__(self, options: InitOptions = InitOptions()): self._option = dict(xAxis=dict(), yAxis=dict()) self.legend() + # TODO: Use 'attr' from base Chart def _update_option(self, **kwargs) -> None: self._option.update(**kwargs) @@ -24,6 +25,10 @@ def _add_series(self, series: dict) -> None: else: self._update_option(series=[series]) + # Pass InitOptions + def configure(self) -> Chart: + return self + def dark(self) -> Chart: self._theme = "dark" return self