support html representations in the notebook frontend #635

Merged
merged 1 commit into from Jul 29, 2011

Conversation

Projects
None yet
2 participants
@minrk
Owner

minrk commented Jul 29, 2011

html repr was inserted has highest priority, because it is the native language of the web frontend.

quick example for embedding YouTube videos in a notebook:

https://gist.github.com/1114390

support html representations in the notebook frontend
html gets highest priority, because it is the native language
of the frontend.
@ellisonbg

This comment has been minimized.

Show comment Hide comment
@ellisonbg

ellisonbg Jul 29, 2011

Owner

Yes I love it! This looks absolutely fantastic. I will merge this and also throw the YouTubeVideo example in the examples directory. My only question is if we want to start to put useful object like your YouTubeVideo class in IPython so others can use them. Maybe in lib?

Owner

ellisonbg commented Jul 29, 2011

Yes I love it! This looks absolutely fantastic. I will merge this and also throw the YouTubeVideo example in the examples directory. My only question is if we want to start to put useful object like your YouTubeVideo class in IPython so others can use them. Maybe in lib?

@minrk

This comment has been minimized.

Show comment Hide comment
@minrk

minrk Jul 29, 2011

Owner

It's such trivial code that I don't think it belongs in lib, but probably does belong in docs when we write them. Maybe if we write a small tool that is more general - supporting youtube, vimeo, etc.

A RawHTML object might be more useful, so that people can dump arbitrary HTML into the frontend. Something like:

class RawHTML(object):
    def __init__(self, src):
        self.src = src

    def _repr_html_(self):
        return self.src

    def draw(self):
        from IPython.core.display import display
        display(self)
Owner

minrk commented Jul 29, 2011

It's such trivial code that I don't think it belongs in lib, but probably does belong in docs when we write them. Maybe if we write a small tool that is more general - supporting youtube, vimeo, etc.

A RawHTML object might be more useful, so that people can dump arbitrary HTML into the frontend. Something like:

class RawHTML(object):
    def __init__(self, src):
        self.src = src

    def _repr_html_(self):
        return self.src

    def draw(self):
        from IPython.core.display import display
        display(self)
@ellisonbg

This comment has been minimized.

Show comment Hide comment
@ellisonbg

ellisonbg Jul 29, 2011

Owner

On Fri, Jul 29, 2011 at 12:51 PM, minrk
reply@reply.github.com
wrote:

It's such trivial code that I don't think it belongs in lib, but probably does belong in docs when we write them. Maybe if we write a small tool that is more general - supporting youtube, vimeo, etc.

But think about very intro users who could easily find the id of a
YouTubeVideo, but wouldn't have a clue about how to find the HTML for
embedding. I was just looking at soundcloud to see if we could create
an MP3 object that 1) could embed a player with display and 2) use
pyaudio or similar to provide the raw audio data as a numpy array.
For audio work that would be killer.

A RawHTML object might be more useful, so that people can dump arbitrary HTML into the frontend.  Something like:

I do like this idea. We could also have other basic things like
RawJSON, RawLatex, RawJavascript in lib as well.

class RawHTML(object):
   def __init__(self, src):
       self.src = src

   def _repr_html_(self):
       return self.src

   def draw(self):
       from IPython.core.display import display
       display(self)

Reply to this email directly or view it on GitHub:
#635 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

ellisonbg commented Jul 29, 2011

On Fri, Jul 29, 2011 at 12:51 PM, minrk
reply@reply.github.com
wrote:

It's such trivial code that I don't think it belongs in lib, but probably does belong in docs when we write them. Maybe if we write a small tool that is more general - supporting youtube, vimeo, etc.

But think about very intro users who could easily find the id of a
YouTubeVideo, but wouldn't have a clue about how to find the HTML for
embedding. I was just looking at soundcloud to see if we could create
an MP3 object that 1) could embed a player with display and 2) use
pyaudio or similar to provide the raw audio data as a numpy array.
For audio work that would be killer.

A RawHTML object might be more useful, so that people can dump arbitrary HTML into the frontend.  Something like:

I do like this idea. We could also have other basic things like
RawJSON, RawLatex, RawJavascript in lib as well.

class RawHTML(object):
   def __init__(self, src):
       self.src = src

   def _repr_html_(self):
       return self.src

   def draw(self):
       from IPython.core.display import display
       display(self)

Reply to this email directly or view it on GitHub:
#635 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@minrk

This comment has been minimized.

Show comment Hide comment
@minrk

minrk Jul 29, 2011

Owner

That makes sense. We should probably start a lib/web for working with various websites, etc.

Is there a functional (not class-based) way to draw raw HTML/JSON/etc? I quite dislike having a class that wraps a single raw string for use in a single method, but I don't know a simpler way.

There should be something like display_raw_html(htmlstring) that does the most basic construction/publishing of the message, without any type-formatters being called.

Owner

minrk commented Jul 29, 2011

That makes sense. We should probably start a lib/web for working with various websites, etc.

Is there a functional (not class-based) way to draw raw HTML/JSON/etc? I quite dislike having a class that wraps a single raw string for use in a single method, but I don't know a simpler way.

There should be something like display_raw_html(htmlstring) that does the most basic construction/publishing of the message, without any type-formatters being called.

@ellisonbg

This comment has been minimized.

Show comment Hide comment
@ellisonbg

ellisonbg Jul 29, 2011

Owner

On Fri, Jul 29, 2011 at 1:37 PM, minrk
reply@reply.github.com
wrote:

That makes sense.  We should probably start a lib/web for working with various websites, etc.

Is there a functional (not class-based) way to draw raw HTML/JSON/etc?  I quite dislike having a class that wraps a single raw string for use in a single method, but I don't know a simpler way.

Not yet, but we should have such a function.

There should be something like display_raw_html(htmlstring) that does the most basic construction/publishing of the message, without any type-formatters being called.

Yes and these functions could just call put the string in a
RawHTML/RawJSON class and return it.

Cheers,

Brian

Reply to this email directly or view it on GitHub:
#635 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

ellisonbg commented Jul 29, 2011

On Fri, Jul 29, 2011 at 1:37 PM, minrk
reply@reply.github.com
wrote:

That makes sense.  We should probably start a lib/web for working with various websites, etc.

Is there a functional (not class-based) way to draw raw HTML/JSON/etc?  I quite dislike having a class that wraps a single raw string for use in a single method, but I don't know a simpler way.

Not yet, but we should have such a function.

There should be something like display_raw_html(htmlstring) that does the most basic construction/publishing of the message, without any type-formatters being called.

Yes and these functions could just call put the string in a
RawHTML/RawJSON class and return it.

Cheers,

Brian

Reply to this email directly or view it on GitHub:
#635 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@minrk

This comment has been minimized.

Show comment Hide comment
@minrk

minrk Jul 29, 2011

Owner

I disagree with the last point - if we have the function, the RawX classes are entirely pointless.

Owner

minrk commented Jul 29, 2011

I disagree with the last point - if we have the function, the RawX classes are entirely pointless.

@ellisonbg

This comment has been minimized.

Show comment Hide comment
@ellisonbg

ellisonbg Jul 29, 2011

Owner

On Fri, Jul 29, 2011 at 2:02 PM, minrk
reply@reply.github.com
wrote:

I disagree with the last point - if we have the function, the RawX classes are entirely pointless.

Not entirely. The functions would render immediately, the classes not
until display was called or they are returned by the displayhook. The
classes would allow HTML to be constructed but not rendered until
later, which could be quite useful. For example, you might have a set
of objects that each have a RawHTML object. You may want to combine
those in some manner before the final display. The objects could also
provide additional APIs for working with the formats. Fro example,
you might want methods of RawHTML to convert between the ElementTree
and plain HTMl text representations of the data.

But if we want to implement the functions to not have to rely on the
classes, that can be done. We are almost there already in the
publish_display_data function of IPython.core.displaypub. Any such
functions should probably be added in that module.

Cheers,

Brian

Reply to this email directly or view it on GitHub:
#635 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

ellisonbg commented Jul 29, 2011

On Fri, Jul 29, 2011 at 2:02 PM, minrk
reply@reply.github.com
wrote:

I disagree with the last point - if we have the function, the RawX classes are entirely pointless.

Not entirely. The functions would render immediately, the classes not
until display was called or they are returned by the displayhook. The
classes would allow HTML to be constructed but not rendered until
later, which could be quite useful. For example, you might have a set
of objects that each have a RawHTML object. You may want to combine
those in some manner before the final display. The objects could also
provide additional APIs for working with the formats. Fro example,
you might want methods of RawHTML to convert between the ElementTree
and plain HTMl text representations of the data.

But if we want to implement the functions to not have to rely on the
classes, that can be done. We are almost there already in the
publish_display_data function of IPython.core.displaypub. Any such
functions should probably be added in that module.

Cheers,

Brian

Reply to this email directly or view it on GitHub:
#635 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@minrk

This comment has been minimized.

Show comment Hide comment
@minrk

minrk Jul 29, 2011

Owner

There could certainly be a use for a more advanced class for containing HTML, but display_raw_html(html_string) should not instantiate or return a class of any kind, and a purely basic RawHTML class like the one I sketched above would be perfectly useless once the raw display function exists.

Owner

minrk commented Jul 29, 2011

There could certainly be a use for a more advanced class for containing HTML, but display_raw_html(html_string) should not instantiate or return a class of any kind, and a purely basic RawHTML class like the one I sketched above would be perfectly useless once the raw display function exists.

@ellisonbg

This comment has been minimized.

Show comment Hide comment
@ellisonbg

ellisonbg Jul 29, 2011

Owner

On Fri, Jul 29, 2011 at 2:18 PM, minrk
reply@reply.github.com
wrote:

There could certainly be a use for a more advanced class for containing HTML, but display_raw_html(html_string) should not instantiate or return a class of any kind, and a purely basic RawHTML class like the one I sketched above would be perfectly useless once the raw display function exists.

Sounds good.

Reply to this email directly or view it on GitHub:
#635 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

ellisonbg commented Jul 29, 2011

On Fri, Jul 29, 2011 at 2:18 PM, minrk
reply@reply.github.com
wrote:

There could certainly be a use for a more advanced class for containing HTML, but display_raw_html(html_string) should not instantiate or return a class of any kind, and a purely basic RawHTML class like the one I sketched above would be perfectly useless once the raw display function exists.

Sounds good.

Reply to this email directly or view it on GitHub:
#635 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@ellisonbg ellisonbg merged commit 1cc83a7 into ipython:htmlnotebook Jul 29, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment