Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Followup to Conditional HTML Styling #11610
Comments
TomAugspurger
added this to the
0.17.1
milestone
Nov 16, 2015
TomAugspurger
added Output-Formatting IO HTML
labels
Nov 16, 2015
|
@TomAugspurger I had to slightly change |
|
A comment on the API of the highlighter:
This basically only works for html representation ("color: red" is css speak) and assumes that the return value should got to the css. In latex (see e.g. this example), you prefix/suround the value with a command:
would render the second cell blue (by using a command from a special package). So for latex you probably need templates ala |
kynan
commented
Nov 16, 2015
|
@TomAugspurger I think you made a great start on this! A few ideas for making this approach potentially more flexible:
This extends the previous suggestion and would allow using exported html tables with any kind of JavaScript library using specific attributes. Sorry for being so late in making these suggestions - I didn't manage to read through all of #10250 before it was merged. |
|
@kynan fantastic, thanks for the feedback. I'll go through it in more detail later. Your item 1. sounds pretty simple. Is |
kynan
commented
Nov 16, 2015
|
@TomAugspurger I believe attribute is the common term and also the one the W3C uses. |
jreback
closed this
in #11634
Nov 18, 2015
jreback
reopened this
Nov 18, 2015
|
@TomAugspurger merged your PR; I'll leave you to close when you are ready. |
|
Thanks, I want to get a better solution in place for including notebooks in the sphinx build, but that works for now. @kynan, for your second item, assigning classes to cells. My current thinking is to have a method on |
|
docs are up if anyone sees anything. It does still have the [In] and [Out] tags and ¶ markers I might be able to hide. |
|
@TomAugspurger yep look great! on the css side, I think its possible if we tag with the SAME names, e.g.
then as long as you tag THOSE cells with that class it would work. we could have default class names (based on the function name), and have this kw to override. |
|
The This could be my limited understanding of CSS, but I don't see how you could accomplish I suppose we could add a data attribute to each cell with the value of that cell... You might be able to pull off some CSS wizardry to accomplish it in that case, but I don't see the average python use being able to write or customize that. |
|
@TomAugspurger I think you would actually construct the classes WITH the in this case the level embedded, (for some you wouldn't need to do this), maybe something like 'gradient_level_0_class` (e.g. say you ten levels of gradient. but this is a refinement. |
jreback
modified the milestone: Next Major Release, 0.17.1
Nov 18, 2015
mattilyra
commented
Nov 20, 2015
|
I've been playing around with the new styling features and have a few comments, overall this is a great new addition. The
The documentation is also a little confusing in terms of debugging the styling functions.
The full stop and space between
|
jreback
modified the milestone: 0.18.0, Next Major Release
Nov 20, 2015
jreback
referenced
this issue
Nov 20, 2015
Closed
Conditional HTML styling hides MultiIndex structure #11655
|
On your first point, I agree that would be useful. If we end up going with a I just pushed a PR to clarify the documentation. That was confusing, thanks. |
|
@TomAugspurger to repeat, awesome work! A question on the 'provisional status'. First, as I said on gitter, I think it is a good idea to put the same provisional note from the notebook in the whatsnew note (experimental = can still change + feedback wanted). Question for the docs: the built notebook in html form is still in the source code. Is this on purpose? (as eg in the latest PR you only updated the notebook and not the html file) |
|
Having the generated HTML is not intended, I thought I deleted that. I'll remove it in my PR adding the provisional note. For the warning. I never was a fan of always getting the warnings when using IPy widgets. I can go either way though. At the very least I'm going to add a note to the docstring for Styler. |
|
Another small note on the docs: maybe it would be good to include a link the notebook on nbviewer? As this actually still looks better than the one included in the docs (the table styling (the borders) is 'uglier') |
|
I was trying to figure out how to include a link that points to the same version of the notebook, but adding the link changes the notebook :) I suppose we just link to |
|
@TomAugspurger we can host a rendered version on github doesn't render these properly AFAICT |
|
I think putting a link 'See this notebook on nbviewer' that points to the one in master is OK (to be fully correct, it should point to the version in the version tag, but that is bit difficult as that does not yet exist :-)) |
|
Just iterate on the links until they converge :) Just pushed pydata#11664 with an NBviewer link pointing to master until we get the version uploaded to |
|
hmm, so this is the argument then for including the nbconvert outputted |
|
A possible advantage of using the link to nbviewer, is that it is then easier to download the notebook to run things yourself |
|
Yeah I think we should definitely link to nbviewer since they already have the stuff in place to download as a link. I'm not sure how including the rendered HTML in the doc build helps (or hurts) with this. |
|
OK, merging the PR then! |
|
The first SO questions appear! :-) |
jreback
added the
Master Tracker
label
Nov 25, 2015
|
@TomAugspurger let's try to link all relevant HTML issues at the top of the tracker (as most/maybe all can be accomplished via |
|
xref #11700 |
kynan
commented
Nov 25, 2015
|
@TomAugspurger Sorry for the delay. |
121onto
commented
Nov 26, 2015
|
This feature looks really promising. Thanks all who worked on it! Wouldn't it be great if I could render DataFrames in html outside of ipython notebooks!? I'm not a fan of developing inside ipython notebook, and working with matplotlib entails a lot of overhead. Two workflows that come to mind are as follows. First, if you are working on a mac, keep a quicklook window open on a PDF file that you use to store current output. Then, define a from weasyprint import HTML
def my_style(frame):
return frame.style.highlight_null(null_color='red') # or whatever
def my_print_pdf(frame, styler, filename='/Users/username/temp/frame_viewer.pdf'):
style = styler(frame)
html = HTML(style.render())
html.write_pdf(filename)
return NoneThe Quicklook should update each time you Second, use something like Browsersync to watch an HTML file. To watch a file with Browsersync, you'd type the following in your terminal: cd ~/temp
browser-sync start --server --index "frame_viewer.html" --files "*.html"With this approach, you'd write a def my_print_html(frame, styler, filename='/Users/username/temp/frame_viewer.html'):
style = styler(frame)
html = "<html><head></head><body>" + style.render() + "</body></html>"
with open(filename, 'w') as f:
print(html, file=f)
return NoneEach time you call Notes: code not tested. Edits 1: tested Browsersync example and updated code so it works on my machine. |
|
Those are both possible now right? You'd just need to write the code / startup the server? Something like your code would fit well in the cookbook documentation. Adding "builtin" support for rendering in the notebook had a very favorable cost-benefit ratio. Two lines of code for something used by so many. I don't anticipate adding other backends.
|
121onto
commented
Nov 26, 2015
|
@TomAugspurger yes, possible right now. The Browsersync example should work now. |
|
@TomAugspurger just came across this from |
|
This is an interesting approach in R: https://github.com/renkun-ken/formattable -> see the last example |
joekane3
commented
Dec 15, 2015
|
@joekane3 something like that should be possible through the Of course, you'll have to do all the conversion from values to colors on your own. Pandas just uses matplotlib internally, so that's probably your best bet. |
monkh
commented
Dec 30, 2015
|
I'm new to github, sorry if this is wrong place to post this. Also it seems like the Styler is going to (in the future) make .to_html() obsolete. |
|
Correct, the index is unstyleable right now. I plan to fix that in the future, including an option to hide it. We'll always have to_html, but the implementation might reuse the code here. |
This was referenced Jan 7, 2016
jreback
modified the milestone: 0.18.1, 0.18.0
Feb 13, 2016
TomAugspurger
added the
Style
label
Mar 11, 2016
TomAugspurger
referenced
this issue
Mar 11, 2016
Closed
Include index names in column names of HTML output of DataFrame Style… #12598
jreback
modified the milestone: 0.18.1, Next Major Release
Apr 26, 2016
jreback
referenced
this issue
May 11, 2016
Closed
df.style des not render pivot tables in the same fashion as to_html #13140
TomAugspurger
removed the
Style
label
May 17, 2016
jorisvandenbossche
referenced
this issue
Jun 6, 2016
Open
ENH: write Styler rendered output to file #13379
mjmyers
commented
Jul 18, 2016
@TomAugspurger : Was there ever any headway on this? I can't find mention of it in the docs. I've had to do some pretty hacky css to hide the index while using the styler. |
|
actually a bit of work here: pydata#11655 |
|
@mjmyers nothing for styling the index yet though. The The big thing is finding an API that's nice to work with. Some possibilities
But I haven't thought too much about it yet. |

TomAugspurger commentedNov 16, 2015
Follows #10250
For 0.17.1
doc/source/html-styling.htmland find a way to includedoc/source/html-styling.ipynbin the doc build (should use--template=basic)print_versionsrequirements_all.txtto include jinjaFor 0.18.0 / Future
imgtags, urls, etc. flows into...Styler.templateinto smaller blocks. Let people extend that. We could (maybe) allow users to choose which template to use to render each column/cell with solving the template modification problempd.options, allow setting of default reprs with stylesStylerinto aBaseStyler, maybe add a LaTeX styler (maybe deprecate / replace theto_htmlandto_latexmethods; Jinja templates are much more pleasant to work with), xref #11700will add more as we go.