Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to publish raw/encoded display data #946

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jlumpe
Copy link
Contributor

@jlumpe jlumpe commented Aug 18, 2020

Added a display_data function which takes raw/encoded data to display in the front end. The first form accepts a single MIME type and a data string or JSON-able value, the second takes a MIME bundle.

display(::InlineDisplay, ...) methods are updated to use this function instead of explicitly constructing the message and calling send_ipython.

I added a detailed docstring and listed it under the public API in the documentation.

This works when I tested it manually, I don't know how to write a unit test for it though.

@jlumpe
Copy link
Contributor Author

jlumpe commented Aug 18, 2020

Closes #934, can use display_data("application/json", json_value).

@jlumpe
Copy link
Contributor Author

jlumpe commented Sep 6, 2020

@stevengj does this seem useful?

@stevengj
Copy link
Member

I'd rather have this as a method of display

@jlumpe
Copy link
Contributor Author

jlumpe commented Nov 15, 2020

@stevengj what exactly would the method be? I feel like this is a somewhat different concept than Base.display, in that the expected arguments are in a different format. display_data is low-level and takes pre-encoded JSON or binary data. display(::InlineDisplay, ...) is high level and takes an argument of any type which is passed to display_dict first.

Another way of looking at it - display(::InlineDisplay, ...) is a method of a function in Base which has an expected behavior, independent of any of the particulars of Jupyter's display system. display_data takes raw display data in Jupyter's specific but well-documented format (MIME bundle). There is some process within display which converts an arbitrary value to a MIME bundle. Right now it's just a call to display_dict, but I think there is room for improvement to the API to make it easier for developers to customize this process for their own types. I'd like to make some contributions here but I think it is necessary to have a separate display_data function as the endpoint in this process, which is called after the MIME bundle has been created but hides the specifics of the kernel -> front end messaging system.

@jlumpe
Copy link
Contributor Author

jlumpe commented Dec 5, 2020

@stevengj any thoughts on the above?

src/display.jl Outdated
display_data(mime::Union{MIME, String}, data; metadata::Dict=Dict())
display_data(mimebundle::Dict; metadata::Dict=Dict())

Publish raw data to be displayed on all Jupyter front ends.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raw data is never a good term to use,
but here it seems particularly misleading.
that data argument is the output of limitstringmime which means it has already going though a call to rerepresent it.
Which will have for example converted DataFrames to HTML tables, etc etc or anything else that has show(io, mimetype, data) defined on it for any of the registered mime types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like "Publish rich display data to all Jupyter front ends"? I think the rest of the docstring is hopefully pretty clear on the expected format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be.
I don't know enough about what this does to say for sure.
And I don't have merge rights here.

@jlumpe
Copy link
Contributor Author

jlumpe commented Feb 8, 2021

  • Moved new code from src/display.jl to src/inline.jl, where it seems to fit better.
  • Accept AbstractDict for metadata argument and check MIME keys
  • Significantly improved docstring and added usage examples
  • Added ability to update display data at a later time or from a different cell

@jlumpe
Copy link
Contributor Author

jlumpe commented Feb 8, 2021

@stevengj Any way you can take another look at this?

@jlumpe
Copy link
Contributor Author

jlumpe commented Mar 25, 2021

bump?

@jlumpe
Copy link
Contributor Author

jlumpe commented Apr 22, 2021

Latest merge conflicts have been resolved, both display_data and update_display_data methods now call flush_all() before publishing the message (#999).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants