🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

Generate HTML Code in Python

Hi there - every day I generate several new charts and leverage the HTML code generated for sharing on my blog. Is there a way to generate said HTML code in Python without having to manually navigate to my profile, click on each image, and copy the HTLM Code?

Thanks.

I have found .to_html and able to return the html code. However, all I want is the <div> code so I can drop into an html file. Unfortunately, I’m not getting this code even when setting include_plotyjs = False. My code outputs JS code that I don’t want.

I currently have this in my script when calling fig.

fig.to_html('code.html', full_html = False, include_plotlyjs = False, include_mathjax = False, post_script = False)

I have tried this several times over and nothing works.

Dang, a week later and no response from anyone. Suffice it to say, this feature is broken…

Hi @reggiebizzle,

Is my_div, defined below, what you are looking for?

from plotly.offline import download_plotlyjs, init_notebook_mode,   plot
init_notebook_mode(connected=True)
my_div = plot(fig, filename='My title', show_link=False, include_plotlyjs=False, 
                 output_type='div')
print(my_div)

Hi @empet,

That returns a bunch of javascript code as well, even when include_plotlyjs=False . I’d like to get the same that I get when I open up plotly, navigate to my profile, click on an image and navigate to the embedded tab.

Yup, this feature is broken. What an absolute shame.