Using Gadfly interactively in Pluto

430 views Asked by At

I am using Gadfly in Pluto and I am trying to figure out if it is possible to have interactive versions of the plots in Pluto notebooks. If I just use the REPL, Gadfly produces very nice interactive plots that are opened in my web browser:

using Gadfly
plot([sin, cos], 0 , 4)

However, if I use Gadfly in Pluto, the plots that are included in the notebook are not interactive, they are static. This is a simple example of a Pluto notebook:

### A Pluto.jl notebook ###
# v0.12.20

using Markdown
using InteractiveUtils

# ╔═╡ 7bb74118-73d1-11eb-2bd5-c1ef89972288
using Gadfly

# ╔═╡ 9080ac2e-73d1-11eb-18d6-5f85903a7259
plot([sin, cos], 0 , 4)

# ╔═╡ Cell order:
# ╠═7bb74118-73d1-11eb-2bd5-c1ef89972288
# ╠═9080ac2e-73d1-11eb-18d6-5f85903a7259

How can I have interactive versions of the Gadfly plots in Pluto?

Any help is much appreciated!

1

There are 1 answers

0
Diego Javier Zea On

Following the suggestion in https://github.com/fonsp/Pluto.jl/issues/546#issuecomment-705556778

You can define:

struct HTMLDocument
    embedded
end

function Base.show(io::IO, mime::MIME"text/html", doc::HTMLDocument)
    println(io, "<html>")
    show(io, mime, doc.embedded)
    println(io, "</html>")
end

And then do

plot([sin, cos], 0 , 4) |> HTMLDocument

To get the interactive plot in Pluto.

Best,