Ballooning Report Sizes with Plotly

Hi team,

I’m wondering how to add a Plotly figure plot to Datapane without adding all the associated Javascript? Obviously the background JS is ~4MB per plot (before) so I found a my test-Datapane reports ballooning in size (a 1MB report became 30-40MB).

Not sure if this is helpful but I normally chose the ‘cdn’ option; from the docs

fig.to_html(full_html=False, include_plotlyjs='cdn',)

Thanks again! Really liking what Datapane is trying to do.

David

Hi David, thanks for getting in touch. We had a similar issue come up regarding bloated local reports, and the proposed solution was to add an option to load heavy libraries via CDN rather than in-linining their source in the report bundle. I.e.

report.save(path="my_report.html", use_cdn=True)

We’ll hopefully be able to get this out in a release within the next few weeks. Would this solve the issue you’re facing?

Hi Jake,

Yeah, I think that would be a good solution, especially if it’s just in the final report.save() at the end.

I’d played with a workaround which is essentially the same thing:

from markdown import markdown

markdown_fig = markdown(fig.to_html(include_plotlyjs=False))

then adding to Datapane as a markdown element rather than a plot.

Thanks for the project.

David

Hey David, that’s a really cool workaround! I’d never thought of hacking it into a markdown block. We’ll work on officially supporting a CDN option in the meantime.

Thanks

Jake

Hi,

Not sure how close you guys are to a release? But thought I’d highlight that something in the dp.Markdown() may also seem to bloat file sizes. Out of curiosity I’ve built the same report 3-times, once using Datapane (appending Plotly figs as markdown), once with a bare basics Jinja2 template and plotly figs as markdown and Jinja2 inlcluding plotly javascript.

image

Plotly with JS was obviously massive (21MB) but I’d have thought the other 2 would be very similar but my Jinja2 static HTML file was 614KB & the Datapane file was 6.5MB.

It could be that you guys have 6MB of embedded script in your templates? And having a ‘CDN’ option would remove all of that or it maybe something in the Markdown causing the bloating?

All the best,

David

Hi David, the reason the Datapane file is so large is because we bundle all of the assets needed for each block type (Plotly, altair, etc) into the local report regardless of whether they’re needed. We’re currently looking into improving this via either the CDN option (as you suggested) or by code-splitting our local bundle and doing some prior inspection of the report object to determine which bundle sections to include. I’ll be happy to keep you updated when we work a solution out.

Cheers
Jake

Hey David, I’ve created an issue to track this feature. We can continue any further discussion on there. Cheers!

To confirm, this has been fixed to be the default behaviour with save. If you would still like a standalone report, we have added a standalone option to the method.

Is there anything else we can help with here, David?