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
Add String pane to support any representable object #21
Conversation
Codecov Report
@@ Coverage Diff @@
## master #21 +/- ##
==========================================
+ Coverage 92.64% 92.78% +0.14%
==========================================
Files 19 19
Lines 2230 2441 +211
==========================================
+ Hits 2066 2265 +199
- Misses 164 176 +12
Continue to review full report at Codecov.
|
I have no opinion at all here, so far I've only used 0 and 1. I also meant to invert precedences such that a higher value actually gives higher precedence but it seems like leaving it might be more intuitive? I'll leave that up to you.
As long as you give the bokeh model a fixed width it should wrap.
I can't think of a case in which a standard repr would ever contain HTML (unless it's one of the objects parameter values in which case I think it should be escaped). |
After trying it out with a few things, it seems to me that calling Here's an example of using it twice:
The return value from the |
Even if it wraps, it seems like it could go way off the page, but I guess we can worry about that if we encounter it. |
Given that within Panel itself, the main use for precedence is to ensure that certain classes (HTML and String in this case) are not used when there is some other more specific one available, I think inverting the precedence makes sense -- 0 is a nice special value at the low end, but there's no equivalent at the high end. So I'd invert it and use maybe 0.5 as the default precedence, then 0.1 for String, 0.2 for HTML, and leave the other numbers for user stuff. Just my guess... |
Now I'm confused, you said you were okay with inverted precedence but then gave String a lower precedence value (i.e. a higher precedence) than the default? |
We're probably all confused, then! I haven't messed with the code for comparing precedences, which is however you had it. But what I think it should be made to do is for String to be the least preferred (as it always applies), HTML to be the second-least preferred (as it often applies) , and the rest to be the default level of preference. |
Currently lower precedence values are preferred, so the values right now are: 0 - Bokeh, Matplotlib, HoloViews, Plotly, GGPlot etc. So let's take a holoviews object, three panes could apply: HoloViews, Param and String panes. The HoloViews pane wins out because it has the lowest precedence value and therefore the highest precedence. That is confusing and I'm happy to invert precedences such that the higher value wins, but I'm happy to use whatever scheme and values you suggest. |
Ah, Param's precedence is set outside of pane.py, so I didn't notice that one, and HTML currently also has a precedence of 1, which will surely cause problems for any Parameterized object that has a |
I strongly feel showing widgets should be preferred, a String representation of an object should be absolutely the last fallback in a dashboard context. |
I should read more thoroughly, you were talking about a parameterized object with a |
I do not currently have any Parameterized object in Datashader that has a In general I can imagine many objects that one might want to add representations for, where the parameters are for configuration rather than for representing them. Given the choice between representing the object and configuring the object, I think we should choose to represent the object itself wherever a meaningful representation has been defined (including |
I think a limit on the maximum size of the string is a good idea even if bokeh can wrap long strings. I also agree that |
I'm not quite sure of this in
I would prefer to use |
Note that it's not using |
String just puts whatever you give it into a Bokeh Div, so it inherently supports HTML. We could maybe somehow wrap it as raw text to avoid having the HTML markup interpreted (wrap in "pre" tags, maybe?), but I'm not sure if that buys us anything. I guess it would let us show Meanwhile, pane.HTML currently has a guard that makes it be applied only for objects with a |
I think this should be relaxed to allow HTML strings and |
How would we detect that a string was an HTML string? |
If you explicitly use |
Ok, it sounds like you are proposing that the current pane.HTML class should be changed so that it accepts both strings and things that have It would then be confusing that pane.String would never be chosen automatically for a string, but perhaps it could be renamed pane.Str, and what it would mean would be that it calls |
Yes, that is what I meant although I have no opinion about renaming to |
Ok, I think I've implemented what was discussed above:
Here's an example of the results:
As you can see, I decided that it was best to wrap the Str output in This all works fine, but there are a couple of issues:
|
Code changes look good to me and I agree using the The issue about the horizontal spacing between the panes also seems quite general but maybe a string specific fix might be appropriate? You could pad the supplied string with spaces but maybe that is too hackish... |
Right; the vertical height issue applies to both HTML and Str, and presumably any Bokeh Div containing just text. I can't tell if there would need to be one or two fixes for the horizontal and vertical issues, but I do know that adding spaces automatically seems hackish... |
This is a problem with bokeh Divs, which I haven't been able to solve. Without providing an explicit size they won't adapt automatically. |
I organized the list in #2 by "richness", and to make what it says there true (that richer plots are preferred), I've now made interactive plots have a higher precedence than the rest. That way if e.g. HoloViews or any of the other interactive libraries eventually added a |
You can add spacers, but we could also consider adding some padding to Str/HTML panes. |
I've added tests and will merge. |
@jlstevens suggested we add support for a string-based representation for any Python object as a Pane. About 20 minutes after his suggestion, I already realized that I needed that, so here it is.
Adding the Repr class is the only change; the other diffs are just to reorganize the other classes to be in a more readable order.
Questions: