# Generating plotlyjs charts in python

**URL:** <https://community.plotly.com/t/generating-plotlyjs-charts-in-python/40874>\
**Category:** 📊 Plotly Python\
**Created:** [June 11, 2020, 1:08am UTC](https://community.plotly.com/t/generating-plotlyjs-charts-in-python/40874 "2020-06-11T01:08:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joelhoro](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/joelhoro/32/11287_2.png) [@joelhoro](https://community.plotly.com/u/joelhoro)\
**Post date:** [June 11, 2020, 1:08am UTC](https://community.plotly.com/t/generating-plotlyjs-charts-in-python/40874/1 "2020-06-11T01:08:57Z")

</div>

I know that Dash allows to write code to generate a chart that is then viewable in a browser (with zoom/pan controls etc…), but I don’t think I can use Dash as it does not seem to allow me to do certain things (namely, dynamic / variable number of components).

Is there an easy way to do either of the below?

1. using the same python code to generates a plotly.py image server-side, as well as to generate the html/javascript to view it on a webpage, with all the controls? I tried just fig.to\_html() which works fine in a standalone way, but the html/js generated is tricky to integrate on a web page (it seems to be meant more for standalone pages).
2. do matplotlib operations like df.plot(), etc… and get a javascript representation of it? Tried mpld3, it worked in some cases, not in others, seemed buggy

I don’t need fancy charts, all I want is a python fn that generates the json `data` you would normally feed to `Plotly.newPlot('myDiv', data);`

---

<div class="post-metadata">

**Author:** ![joelhoro](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/joelhoro/32/11287_2.png) [@joelhoro](https://community.plotly.com/u/joelhoro)\
**Post date:** [June 11, 2020, 1:38am UTC](https://community.plotly.com/t/generating-plotlyjs-charts-in-python/40874/2 "2020-06-11T01:38:45Z")

</div>

I think I found it, it was as simple as doing fig.to\_json()

Hope I didn’t waste anyone’s time 🙄
