✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

To_plotly_json method


I’m using this little snippet:

import plotly.express as px
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',

to create a plot. But now I want to insert that into a webpage using js, so I used fig.to_plotly_json.
However, when I paste that javascript dictionary into JS, (so I can render it using Plotly.newPlot('graph', data);I keep getting errors indicating that the to_plotly_json method is not actually javascript code. What gives? Can anyone point me in the right direction? thank you!

I didn’t check, but the method returns a py dict, not a json string as I assumed. They happen to look nearly identical! Used json module to convert. Sorry about that.