Sharing Interactive Python Charts as HTML I: One Chart, One File, No Server

Updated: Nov 15
A typical problem when building charts with Python comes when you want someone to see it. They don't use Python, they don't want your environment, they just want to click on things, and they want more than just a saved image.
This post is about one of the options that can be used in this case. We'll use D3Blocks, a Python library that turns DataFrames into interactive D3.js charts, and we'll ask one focused question: how much interactive analysis can we share as a single HTML file before we need a dashboard?
This is not a tour of every chart type. D3Blocks has many, and a catalogue would be a rewritten README. Instead we use one dataset, one sharing task, and we inspect what the recipient really receives.

The Sharing Trilemma
When a chart has to leave your machine, there are usually three options.
A screenshot. Easy to send, impossible to explore. Nobody can ask "what is that node connected to?"
A notebook. Fully interactive, but the recipient needs Python, the right packages, and some patience.
A dashboard. Great experience, but now you operate a service. Hosting, updates, access, someone's pager.
There is a fourth option that gets less attention: generate an HTML file.
The workflow looks like this:
Prepare the data in Python.
Generate the chart as an HTML file.
Send the file.
The recipient opens it in a browser.
Python does the preparation. The browser does the interaction. The recipient never runs your code.
That is the whole pitch. Whether it holds up is what we're here to find out.
What the Browser Actually Does
Before any code, one mental model worth having.
An exported chart is a small web page. It contains three things:
the data (your DataFrame, serialised as JSON or similar)
the rendering code (D3.js plus the chart logic)
the controls (tooltips, search, filters, themes)
Everything after the export happens client-side. Hover, drag, filter, zoom: all JavaScript in the recipient's browser, working on the data that was baked into the file.
Two consequences follow, and we'll keep coming back to both.
The file is a snapshot. If the source data changes tomorrow, the file doesn't know. You regenerate and resend.
Whatever is in the chart is in the file. Every row that powers the visual is, in principle, readable by whoever receives it.
Neither is a flaw. They are simply the structural properties of the approach.
Setup
For what we will use, we will need D3blocks, Pandas, and Numpy.
The whole library hangs off one class:
Every chart is a method on this object: d3.sankey(...), d3.chord(...), d3.d3graph(...), and so on. That consistency is a big part of the appeal. We'll use that later.
The Data Shape Decides the Chart
Most people choose a chart first and then wrestle the data into it. D3Blocks nudges you towards the reverse.
Many of its relationship charts start from the same input: an edge list.
source | target | weight |
Solar | Electricity | 40 |
Gas | Electricity | 60 |
Electricity | Homes | 75 |
Each row is a connection. weight says how strong, large, or frequent it is.
That's it. Once you have this table, you can ask several different questions of it. Let's build a slightly more realistic one.
Ten rows. Small enough to read, structured enough to be interesting.
The Baby Example: A Sankey
The weights are quantities moving from one place to another. That's exactly what a Sankey diagram is for.
Three lines of substance. The result is an interactive diagram: hover a link to see its value, drag nodes to rearrange, and so on.

Two details matter here.
filepath is where the standalone file lands. This is the thing you actually send to people.
showfig=False suppresses the automatic browser launch. Handy in scripts and scheduled jobs. When you're experimenting, leave it on and enjoy the instant feedback loop.
Now the useful part. Don't just admire the chart. Open the file as data.
Look Inside the File
If we claim the output is self-contained, we should be able to check.
Our node names appear in the file text. The data travelled with the chart. Not surprising, but worth seeing with your own eyes once.
Now the more important question. Does the page reach out to the internet?
Three outcomes are possible:
Nothing printed. Everything is embedded. The file should work offline.
A CDN link for D3.js. The chart needs internet access to load its rendering library.
Fonts or images from elsewhere. The chart may look different, or break, on a locked-down network.
When I run this on my machine, I get the output
https://d3blocks.github.io/d3blocks/
https://media.ethicalads.io/media/client/ethicalads.min.jsThe first one here is not that big of a surprise, considering we are using the package, the second one is a bit unexpected. We will leave this for now and come back to this later in as Part 2 of this series.
Same Edges, Different Question
Here's where the "data shape" idea pays off. The same edge list can feed other charts without any new data preparation.
A chord diagram arranges the nodes around a circle and draws ribbons between them. It's good at answering "which groups are most connected?" and less good at showing direction and sequence. The Sankey was left-to-right; the chord is circular and symmetrical.

Or treat it as a general network:
A force-directed graph lets you drag nodes around and see clusters emerge. It shines when you don't know the structure in advance, but struggles when you ask about quantities.

The lesson is not "look how many charts there are". It's which question does each one answer?
Chart | Best at | Weak at |
Sankey | Quantities flowing between stages | Cycles, undirected relationships |
Chord | Strength of connections between groups | Reading exact values, direction |
Force graph | Discovering clusters and hubs | Precise comparison, large dense networks |
If the connection means flow, use a flow chart. If it means association, use something else. The edge list is the same; the meaning is not.
A Small Helper for Experiments
Because the API is so regular, we can write one function to try several views of the same data.
Now you have three candidate views to send, or to put in front of a colleague and ask "which of these answers your question?"
That last step is underrated. Interactive output is not about prettiness. It lets the reader ask follow-up questions you didn't anticipate. It also allows others to give you input before finalizing the chart for a report.
What Interaction Actually Adds
It's worth being specific, because "interactive" is easily the most overused word in data visualisation.
In the energy example, interaction lets a reader:
hover to get the exact number behind a link, instead of squinting at a thickness
drag nodes apart to untangle crossing links
follow one source (say, Gas) through to every destination
None of that changes the data. It changes how many questions the chart can answer without you in the room.
That's the real value of the HTML approach: it moves exploration from your laptop to the reader's browser. Of course, there should be a word of caution, do not just flood the reader with every chart and colour option available and let him choose.
When NOT to Use This
Some situations where a single HTML file is the wrong answer.
The data changes constantly. The file is a snapshot. If readers need today's numbers every morning, you're regenerating and resending, which is a manual dashboard with extra steps.
The audience can't open HTML. Some email systems and document platforms strip or block it. Check where the file will land before falling in love with the format.
The data is sensitive. The data is in the file. Anyone who receives it can open it in a text editor. If a row shouldn't be seen, it shouldn't be in the chart.
You need identity or permissions. A file has no concept of who is looking at it.
None of these make the approach bad. They define its boundaries, which is exactly what a decision guide should do.
What We Have So Far
A recap of the mental model:
An exported chart is a small web page with your data inside it.
Interaction happens in the browser, so the recipient needs no Python.
The shape of your data (here, an edge list) suggests which charts are even possible.
Each chart answers a different question. Choose the question first.
The file is a snapshot, and you should check what it depends on.
So far we've only used a ten-row table, which is a very friendly test. In Part 2 we make things harder: time-based data, bigger inputs, an offline test, a comparison with Plotly, and the moment a dashboard starts to make sense.



Comments