Exporting a Jupyter Notebook widgets slider to html

Viewed 290

I have the following slider figure code run on Jupyter Notebook.

import plotly.graph_objects as go
from ipywidgets import widgets
from plotly.subplots import make_subplots
import numpy as np


x_plot=np.arange(-5,5,0.1)
y_plot=np.arange(-5,5,0.1)
X, Y = np.meshgrid(x_plot, y_plot)

fig = make_subplots(rows=1, cols=2,
                    specs=[[{'is_3d': True}, {'is_3d': True}]],
                    )

fig.add_trace(go.Surface(x=X, y=Y, z=np.cos(X),
                         showscale=False), 1, 1)
fig.add_trace(go.Surface(x=X, y=Y, z=np.cos(X),
                         showscale=False), 1, 2)

ele_slider = widgets.FloatSlider(min=-np.pi/2, max=np.pi/2, value=np.pi/4, description="Elevation")
azi_slider = widgets.FloatSlider(min=0, max=2*np.pi, value=np.pi/4, description="Azimuth")
fig_widg = go.FigureWidget(fig)

r=2.5

fig_widg.layout.scene1.camera.eye=dict(x=r/2, y=r/2, z=r/np.sqrt(2))
fig_widg.layout.scene2.camera.eye=dict(x=r/2, y=r/2, z=r/np.sqrt(2))


def func(change):
    x = r * np.cos(ele_slider.value) * np.cos(azi_slider.value)
    y = r * np.cos(ele_slider.value) * np.sin(azi_slider.value)
    z = r * np.sin(ele_slider.value)
    fig_widg.layout.scene1.camera.eye=dict(x=x, y=y, z=z)
    fig_widg.layout.scene2.camera.eye=dict(x=x, y=y, z=z)    

azi_slider.observe(func, names="value")
ele_slider.observe(func, names="value")
widgets.VBox([ele_slider, azi_slider, fig_widg])

I want to export this slider to html and I was wondering if there is a method like the write_html method in plotly or it is not possible to export from this.

0 Answers
Related