Plotly Link#
import numpy as np
import panel as pn
pn.extension('plotly', template='bootstrap')
Since Plotly plots are represented as simple JavaScript objects, we can easily define a JS callback to modify the data and trigger an update in a plot:
xs, ys = np.mgrid[-3:3:0.2, -3:3:0.2]
contour = dict(ncontours=4, type='contour', z=np.sin(xs**2*ys**2))
layout = {'width': 600, 'height': 500, 'margin': {'l': 8, 'b': 8, 'r': 8, 't': 8}}
fig = dict(data=contour, layout=layout)
plotly_pane = pn.ui.Plotly(fig, width=600, height=500)
buttons = pn.ui.RadioButtonGroup(value='Medium', options=['Low', 'Medium', 'High'], color="success")
range_callback = """
var ncontours = [2, 5, 10]
target.data[0].ncontours = ncontours[source.active]
target.properties.data.change.emit()
"""
buttons.jslink(plotly_pane, code={'active': range_callback})
pn.ui.Column(buttons, plotly_pane).servable()
Traceback (most recent call last):
File "/Users/runner/work/panel/panel/panel/io/mime_render.py", line 165, in exec_with_return
exec(compile(init_ast, "<ast>", "exec"), global_context)
File "<ast>", line 15, in <module>
File "/Users/runner/work/panel/panel/panel/reactive.py", line 966, in jslink
assert_source_syncable(self, mapping)
File "/Users/runner/work/panel/panel/panel/links.py", line 55, in assert_source_syncable
raise ValueError(
ValueError: Could not jslink 'active' parameter (or property) on RadioButtonGroup object because it was not found. Similar parameters include: .