Davide-sd / sympy-plot-backends

An improved plotting module for SymPy
BSD 3-Clause "New" or "Revised" License
44 stars 10 forks source link

Exporting interactive widgets to HTML doesn't not preserve "links" between sliders and plot #39

Closed chubby1968 closed 7 months ago

chubby1968 commented 7 months ago

I've tried exporting an interactive widget to HTML using embed_minimal_html from ipywidget. All components of the widgets are displayed, but the plot does no longer respond to changes on parameters. E.g. below where changing the sliders for a and b doesn't update the plot.

Sidenote: LaTeX doesn't seem to render in interactive plots (also before export).

from sympy import *
from spb import *
from ipywidgets.embed import embed_minimal_html
p = plot( a*x+b, params={a: (1,-5,5), b: (2,-5,5)}, ylim=(-10,10),backend=PB)
embed_minimal_html('export.html', views=[p], title='Widgets export')

image

Davide-sd commented 7 months ago

I see what you are trying to do. You would like to write a symbolic expression and generate an html file that can be executed without Python, using only Javascript on the browser. However, this plotting module is based on Python and requires it to run. The logic to create and update the data is all written in Python. I honestly don't think there is something so advanced that can convert that logic it to Javascript on the fly.

chubby1968 commented 7 months ago

Thanks for the quick reply and clearing things up.

I thought it might be possible due to the widget you display in tutorial 4, some of the code comments in doc-utils and sympy javascript printer.

It's possible to get a widget which is interactive with e.g. Plotly in the sense that you can interact with the plot, but not the underlying model.

It makes sense that for it to work also with the model parameters you would manually need to write the logic to update the plot data in e.g. a Plotly figure.