Showing plots within DataFrames.jl + Plots.jl

I did try broadcasting display over the vector of plots (e.g. display.(arrplots)) and it works. I’m not sure how to do this with a DataFrame so I can display all of the columns.

I did play around with PrettyTables.jl as pdeffebach pointed to before and found workablesolution (although not displaying inline) using pretty_table and output to a HTML file.

using DataFrames
import PrettyTables

# kind of a hack to deal with a `Plot`. The `show()` method for a MIME("text/html") has newlines in it
function PrettyTables._parse_cell_html(cell::Plots.Plot{Plots.GRBackend}; kwargs...)
    replace(sprint(show, MIME("text/html"), cell),"\n"=>"")
end

arrplots = [
    plot(1:10, rand(10), size=(170,95), legend=false) for _ in 1:3
]

df = DataFrame(:A => rand(3), :B => arrplots)

open("plot_output.html", "w") do f
   PrettyTables.pretty_table(f, df, backend = :html, renderer = :show)
end

I got the following output:

I’ve mostly been working in Python in the past few years… but my recent experience working in Julia has been a lot of fun because of little things like this. It probably would’ve taken me longer for me to do this in Python!

3 Likes