# \[WIP\] Figures.jl - Draggable interactive figures for plots in a browser

**URL:** https://discourse.julialang.org/t/wip-figures-jl-draggable-interactive-figures-for-plots-in-a-browser/22590
**Category:** Package Announcements
**Tags:** plotting
**Created:** [April 1, 2019, 9:32am UTC](https://discourse.julialang.org/t/wip-figures-jl-draggable-interactive-figures-for-plots-in-a-browser/22590 "2019-04-01T09:32:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)
#### Post date: [April 1, 2019, 9:32am UTC](https://discourse.julialang.org/t/wip-figures-jl-draggable-interactive-figures-for-plots-in-a-browser/22590/1 "2019-04-01T09:32:44Z")

</div>

Hello 👋

This is a little package I threw together a while ago and have kicked it around enough that it might be worth sharing.

> **[GitHub - EricForgy/Figures.jl: Draggable interactive figures for plots in a...](https://github.com/EricForgy/Figures.jl)**
>
> Draggable interactive figures for plots in a browser - GitHub - EricForgy/Figures.jl: Draggable interactive figures for plots in a browser

It is still a work-in-progress, but I’d love to get some feedback / suggestions if anyone is interested.

The idea is to use a blank browser page as something like a desktop to hold interactive draggable plotting windows.

For instance, you can startup a local server by runing

```julia
julia> using Figures; Figures.examples()

```

and open a browser to [http://localhost:8000/examples/blank](http://localhost:8000/examples/blank), where you will be greeted by a completely blank web page. Woo hoo! 🎉😊

Then from the REPL, you can run

```julia
julia> figure(1)

```

and a draggable figure appears.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/2/f2fd36537340de5d51ce9f2140ddecf2d7172949.png)

To avoid conflicts with `plotly.js`, the draggable zone, i.e. the area you need to click to drag the window, is a small strip along the top of the figure window. Double clicking the top strip deletes the figure.

The first version of `Figures.jl` used `PlotlyJS.jl`, but I decided to just write my own `plotly.js` API instead and avoid the dependency (e.g. `PlotlyJS.jl` depends on `Blink.jl`).

```julia
import Figures: Scatter, Layout, Config, Title # I should probably export these 😅
function example_plotly(id,n=10)
    data = [Scatter(;x=1:n,y=rand(n))]
    layout = Layout(;
        title = Title(text="Create a new figure and plot a single trace"),
        width = 650,
        height = 450
    )
    config = Config(displayModeBar=false)
    Plotly.newPlot(id,data,layout=layout,config=config)
end

```

then

```julia
julia> example_plotly("Plot1",50)

```

gives

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/4/e4b720f996370f3aa8cb325fb9eaf0e2a70fdf9d.png)

If you run the function again with the same name (i.e. `div` id), it will put the chart in the same figure.If you give it a new name, it will create a new figure, e.g.

```julia
julia> example_plotly("Plot2",50)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/f/6f7077ef84a91be37fd30fc53b32bf67d0822591.png)

As mentioned, the figures can be dragged around and placed wherever forming a kind of dashboard.

I like `plotly.js` because it is web based and interactive. `Figures.jl` preserves all of the `plotly.js` interactivity, e.g. data tips upon hovering the mouse over data

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/b/5bca73407c9205bb9edc294407cd7be35c9e9fa6.png)

zooming in on a region

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/3/03e2f6e9a49816893769a4223b56205ee16a89cc.png)

etc.

There is a more detailed example if you open the browser to [http://localhost:8000/examples/plot.ly](http://localhost:8000/examples/plot.ly), you’ll see two buttons:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/c/bcd1659577d579ef85085ff206a6687dcdec9bfc.png)

Clicking “Generate Plots” will send a message to Julia via callback to generate 4 plots overlaid on top of each other that can be arranged however you like:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/0/a0880c512fab4de0553ac2e52499af2bb8d4d6db.png)

There is a little fancy trick here. If you open a second tab and view the windows side by side, the “Broadcast Plots” will send the plots to all open windows, i.e. one window is control the display of another window.

Aside from the new Plotly API (which was more work than I’d like to admit), this is all pretty simple stuff. No rocket science here, but I expect it to be useful for my research and hope maybe someone else finds it interesting as well 😊

---

<div class="post-metadata">

### Author: ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)
#### Post date: [April 1, 2019, 9:47am UTC](https://discourse.julialang.org/t/wip-figures-jl-draggable-interactive-figures-for-plots-in-a-browser/22590/2 "2019-04-01T09:47:57Z")

</div>

Nice work! From the example code, I see that you use your Pages.jl package to implement the button that trigger Julia code. Is there a plan to provide some other widgets (as part of Figures) to send data back to Julia, such as sliders, or mouse-position when clicking in the charts? Not sure if that is even feasible within Plotly charts…

---

<div class="post-metadata">

### Author: ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)
#### Post date: [April 1, 2019, 9:51am UTC](https://discourse.julialang.org/t/wip-figures-jl-draggable-interactive-figures-for-plots-in-a-browser/22590/3 "2019-04-01T09:51:51Z")

</div>

Hi @leethargo 👋

Thanks 😊

> Is there a plan to provide some other widgets (as part of Figures) to send data back to Julia, such as sliders, or mouse-position when clicking in the charts? Not sure if that is even feasible within Plotly charts…

Another thing I like about `plotly.js` is that it is built on top of `d3.js` so yes, it is absolutely feasible to add widgets, mouse positions etc. It is just a matter of priorities. If there was something in particular, I could prioritize that 😊

---

<div class="post-metadata">

### Author: ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)
#### Post date: [April 1, 2019, 10:13am UTC](https://discourse.julialang.org/t/wip-figures-jl-draggable-interactive-figures-for-plots-in-a-browser/22590/4 "2019-04-01T10:13:40Z")

</div>

> [@anon67531922](#):
>
> It is just a matter of priorities. If there was something in particular, I could prioritize that

You better prioritize according to your own needs 😉

I’m currently playing with Makie for interactive visualizations of a graph, where I want to, e.g. highlight edges of a node when clicking near that node, but also allow editing of the graph structure. I think that this will work out well, but it would be even better to have something that works in the browser.

---

<div class="post-metadata">

### Author: ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)
#### Post date: [April 1, 2019, 10:19am UTC](https://discourse.julialang.org/t/wip-figures-jl-draggable-interactive-figures-for-plots-in-a-browser/22590/5 "2019-04-01T10:19:13Z")

</div>

That sounds cool 👍

Oh yes. My dream is to allow Makie to work with browsers 😍 This is a babystep in that direction 🙂
