-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Repr html #2421
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
Repr html #2421
Conversation
Hi @emmanuelle, thanks for working on this. Since there are a lot of variations in how to produce an HTML representation of a plotly plot (e.g. in particular there is the choice of We've worked through a lot of this already in the This would allow the user to configure the representation using the renderers system. I haven't looked at what you have here in detail, but it might be that we need a new HTML-based renderer to replicate this functionality. The existing HTML renderer implementations are in Let me know if any of that didn't make sense! |
@jonmmease thanks a lot for your input. I tried to follow your suggestion and
I also had to define a new renderer for my sphinx-gallery application because a renderer can't be both an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @emmanuelle, I'm very happy with this approach and excited for plotly.py to be easier to work with in sphinx gallerey. 💃
if "text/html" in bundle: | ||
return bundle["text/html"] | ||
else: | ||
return self.to_html(full_html=False, include_plotlyjs="cdn") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like the fallback here.
pio.renderers.default = "notebook+plotly_mimetype" | ||
assert set(fig1._repr_mimebundle_().keys()) == set( | ||
{"application/vnd.plotly.v1+json", "text/html"} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for the tests!
Let's merge this a bit later so it will be part of 4.8 and not 4.7.1 ? |
Can I merge this one now that 4.7.1 is out? |
I was actually kind of thinking of doing the lazy-loaded extensions as v4.7.2, along with Plotly.js 1.54.2, this week. Is this a change that can go into a patch? |
I'd rather not to. It is a new functionality, I hope it will not break anything for anybody but one can never be 100% sure so I'd prefer this feature to be released in a .0. No problem for waiting for 4.7.2 first, I just wanted to be sure I would not forget :-). |
This PR proposes to add a
_repr_html_
method togo.Figure
andgo.FigureWidget
, which is a hook used by some notebook-like environments and other packages such as sphinx-gallery. For notebook environments using an ipython kernel,_ipython_display_
has precedence over_repr_html_
(see https://ipython.readthedocs.io/en/stable/config/integrating.html) so this will not change anything.When/if this PR is accepted I will submit a pull request to sphinx-gallery to show a plotly figure on their website (not possible at the moment) since they don't want to user scrapers in their configuration.
@jonmmease