Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Feb 20, 2024
1 parent 09679b3 commit 69b745c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/examples/playground/app2.py
Original file line number Diff line number Diff line change
@@ -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")
5 changes: 5 additions & 0 deletions shinyecharts/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 69b745c

Please sign in to comment.