Problem with ipywidgets and plotly on Databricks
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2025 01:41 AM - edited 04-09-2025 01:44 AM
Hi everyone,
I am encountering a problem when using ipywidgets with plotly on Databricks. I am trying to pass interactive arguments to a function and then plot with plotly.
When I do the following
def f(m, b) :
plt.figure(2)
x = np.linspace(-10, 10, num=1000)
plt.plot(x, m * x + b)
plt.ylim(-5, 5)
plt.show()
interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot
I obtain the expected result. The following code instead
def f(m, b) :
x = np.linspace(-10, 10, num=1000)
y = m * x + b
df = pd.DataFrame({'x': x, 'y': y})
fig = px.line(df, x='x', y='y')
fig.update_yaxes(range=[-5, 5])
fig.show()
interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot
causes the message Latest error: Uncaught ReferenceError: Plotly is not defined.
I am importing plotly.express and the same code runs smoothly locally on my computer.
What could be the problem? Thank you in advance!