Implement show function to make inline result display correctly

I have a struct that wraps a DataFrame, Could I ask how to dispatch Base.show function to make it display correctly in hover results?


Currently, the hover result displays nothing.

You can try something like this:

struct Name
    table::DataFrame
end

Base.show(io::IO, n::Name) = print(io, "$(n.table)")

data = DataFrame()
nm = Name(data)

Which for me prints the same info as for a plain DataFrame.
You can also go check code of packages on github to see more complex options.

Hi, thanks for your answer and it works!
But do you know why calling DataFrames.show(n.table, kwargs...) (I want to customize it a bit) not working? Have been trying different thing for hours :frowning:

Are you thinking about this version of show from the DataFrames package?

As you can see there, the documentation refers to Base.show because DataFrames.jl extends the function from base to their object. Therefore they do not export this method.
Simply, you can use show(DataFrame, kwargs...) just as it is shown in the docs to achieve what you want.

That’s really helpful!!! Learned some Julia tody :slight_smile:
I tweak your example and the result in the terminal is good but the inline result still failed. Do you have any suggestion?

Thank you so much again, I love this community so much!

struct Name
    table::DataFrame
end

Base.show(io::IO, n::Name) = show(n.table; show_row_number=false)

I think this should be

Base.show(io::IO, n::Name) = show(io, n.table; show_row_number=false)

but I don’t know whether that will fix your problem.

1 Like