Can a PlotlyJS plot be exported in a form that includes pan/zoom interactivity?

Hi,

I’m using PlotlyJS to explore some lengthy time series data, and it would be great if I could export a plot with the zoom/pan interactivity. I would like to give it to someone who doesn’t have Julia, as a web page they could open or a small standalone app. Is this supported today?

Thanks.

I haven’t tried this myself but, according to the Plots.jl docs, the plotly/plotlyjs backends support .html files as output (whether or not those .html files also include all the necessary JavaScript for interactivity is something you’ll only know after saving one):

EDIT: I went ahead and tried it and it does indeed save it as an interactive figure (the JavaScript is there):

using Plots
plotly()

p = plot(rand(25),rand(25))

savefig(p, "test.html")
2 Likes

That does work although I don’t need the plotly() line. I am actually using PlotlyJS. One other weird thing, the plot html file only works properly in Chrome (not in Firefox or Edge).

That’s strange. The one that I created with the code above works fine in Chrome and Edge (I didn’t test in another browser). Maybe give it a try via Plots.jl with the plotly backend?

I did this:

using PlotlyJS

p = plot(rand(25),rand(25))

savefig(p, "test2.html")

and the output still works in Edge for me. However, I see a problem that would cause this to fail on another user’s machine. Let me show you the <head> of the two .html files:

via Plots/plotly backend:

    <head>
        <title>Plots.jl</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
    </head>

via PlotlyJS:

<head>
     <script src="C:\Users\mthel\.julia\packages\PlotlyJS\AhkM5\assets\plotly-latest.min.js"></script>
</head>

The first version is bringing in the necessary JavaScript from a CDN (via the web) whereas the second version is storing the necessary JavaScript locally on your machine when you install the PlotlyJS package. The user that you send this .html file to will obviously not have that directory/file available so it will fail.

As a result, if the goal is to generate a .html that you can send to someone else for viewing, it looks like the Plots/plotly route is the better/easier option among these two choices.

You can just replace plot with Plot and it will load the Javascript from the cdn.
I am on v0.13.1 and it works on Edge and IExplorer for me. Maybe you have too restricted security settings concerning Javascript?