Print dataframe in HTML

I have a type that has as one of its fields a AbstractDataFrame:

struct GeoDataFrame{DF<:AbstractDataFrame}
  data::DF
  coordnames::Vector{Symbol}
end

This is how I print the object in plain text:

# compact show
Base.show(io::IO, geodata::GeoDataFrame) = begin
  dims = join(size(geodata.data), "×")
  cnames = join(geodata.coordnames, ", ", " and ")
  print(io, "$dims GeoDataFrame ($cnames)")
end

# multi-line show
Base.show(io::IO, ::MIME"text/plain", geodata::GeoDataFrame) = begin
  println(io, geodata)
  show(io, geodata.data, true, :Row, false)
end

I couldn’t, however; get the “text/html” MIME working. What is the method in DataFrames.jl that I have to call to get the underlying dataframe printed in HTML on Jupyter notebooks?

Base.show(io::IO, ::MIME"text/html", geodata::GeoDataFrame) = Base.show(io, MIME"text/html"(), geodata.data) ?

2 Likes

Oh, I missed that parenthesis after the MIME type in the call, thanks! :slight_smile: