Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECharts depends on sliders fix #1875

Merged
merged 4 commits into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions panel/pane/echarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

from pyviz_comms import JupyterComm

from ..viewable import Layoutable
from .base import PaneBase



class ECharts(PaneBase):
"""
ECharts panes allow rendering echarts.js plots.
"""

object = param.Parameter(default=None, doc="""
The Echarts object being wrapped. Can be an Echarts dictionary or a pyecharts chart""")

Expand Down Expand Up @@ -71,24 +70,18 @@ def _get_model(self, doc, root=None, parent=None, comm=None):
self._models[root.ref['id']] = (model, parent)
return model

def _update(self, ref=None, model=None):
props = {p : getattr(self, p) for p in list(Layoutable.param)
if getattr(self, p) is not None}
echart = self._get_echart_dict(self.object)
self._get_dimensions(echart, props)
props['data'] = echart
model.update(**props)
def _process_param_change(self, msg):
msg = super()._process_param_change(msg)
if 'data' in msg:
msg['data'] = self._get_echart_dict(msg['data'])
return msg

@classmethod
def _get_echart_dict(cls, object):
if object is None:
return {}
if isinstance(object, dict):
return dict(object)
if "pyecharts" in sys.modules:
elif "pyecharts" in sys.modules:
import pyecharts # pylint: disable=import-outside-toplevel,import-error

if isinstance(object, pyecharts.charts.chart.Chart):
return json.loads(object.dump_options())

return {}
18 changes: 17 additions & 1 deletion panel/tests/pane/test_echart.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,25 @@ def get_pyechart():
assert pane.object == bar
return pane

def get_pyechart2():
from pyecharts.charts import Bar
import panel as pn

bar1 = pn.widgets.IntSlider(start=1, end=100, value=50)
bar2 = pn.widgets.IntSlider(start=1, end=100, value=50)

@pn.depends(bar1.param.value, bar2.param.value)
def plot(bar1, bar2):
my_plot= (Bar()
.add_xaxis(['Bar1', 'Bar2'])
.add_yaxis('Values', [bar1, bar2])
)
return pn.pane.ECharts(my_plot, width=500, height=250)
return pn.Row(pn.Column(bar1, bar2), plot)

if __name__.startswith("bokeh"):
# test_echart().servable()
get_pyechart().servable()
get_pyechart2().servable()
if __name__.startswith("__main__"):
test_echart().show(port=5007)
get_pyechart().show(port=5007)