PlutoPlotly.jl

Author JuliaPluto
Popularity
28 Stars
Updated Last
1 Year Ago
Started In
February 2022

PlutoPlotly.jl

This package provides a wrapper type PlutoPlot around the Plot type from PlotlyBase.jl that exposes the plotly library.

The wrapper mostly defines a custom show method specifically optimized for displaying inside of Pluto.jl and adds the options of providing custom javascript functions to attach to the plolty JS events

Basic use of this package is to load this inside Pluto instead of PlotlyBase or PlotlyJS, and then simply wrap the intended Plot objects from PlotlyBase inside a PlutoPlot as

p = Plot(args...)
PlutoPlot(p)

One could also used the convenience exported function plot:

function plot(args...;kwargs...) 
	@nospecialize
	PlutoPlot(Plot(args...;kwargs...))
end

Features

Persistent Layout

The custom show method relies on the Plotly.react function, which is optimized for updating or re-plotting data on an existing graph object, making it ideal in combination with Pluto's reactivity. The data transfer between Pluto and the browser also exploits Pluto's own publish_to_js function which is usually faster than standard JSON serialization, especially for big datasets.

One advantage of using react as opposed to newPlot from the Plotly library is that one can have the layout (e.g. zoom level, camera view angle, etc...) persist across reactive re-runs by exploiting the uirevision attribute of Plotly layouts:

60a529f3-c747-4259-bafb-ddcedcf5bfbc.mp4

Return values to Julia using @bind

The possibility of attaching event listeners to the plotly events allows to create nice interactivity between Julia and Pluto using the @bind macro

Coordinates of the clicked point

7ef3a455-4015-4012-9025-2415f8061851.mp4

Filtering only visible points in the plot

8a8b3f85-988b-4865-958f-da8a66ad008e.mp4

View the wrapper notebook for more details and examples.