Add a "show_in_browser" feature for tables#1342
Conversation
|
Ohh, nice! Works great with Python 2.7. Note, it doesn't work in Python 3: |
|
Just a suggestion - maybe the web browser version could include some CSS to add light lines between cells (excel-style)? |
|
Yes, CSS formatting would be nice, I'll add that as an option. Maybe an Any thoughts on how to test this? Will Travis behave sanely with
|
|
Also, I don't think I understand the python3 error - is it complaining that I'm trying to write unencoded strings? |
|
I don't think any more formatting work should be added on this PR without going a whole next level of making a "table browser" class. I could imagine creating a class where you build in your own css formatting, header, etc, and maybe even building in javascript callbacks for, e.g., sorting. |
|
The CSS doesn't seem to work here (will examine why later). Also, my feeling is that the server, once created, should live until the Table is garbage collected, otherwise doing e.g. 'refresh' causes the page to disappear. +1 to the idea of making an HTML-based table browser! @taldcroft might want to see this. |
|
Agreed, the webbrowser should live for a while... when should it be killed, though? I'm not sure there's a good way to make that decision, except perhaps to let it die when the python session dies. I think the latest commit will make that happen for most use-cases though. |
|
I think the only way to have the server live forever is to have it run in its own thread, correct? Dealing with threads, particularly in a way that works will in a library usable in a number of contexts is going to be very hard to get right. I'd say let's avoid that and keep the scope of this to something that sends the data to the browser once and then immediately goes away. Also, keeping it around for the whole session would also imply keeping a reference to the data for the whole session, possibly leading to a "memory leak" (in quotes because it's just an unintentional keeping of references, not an uncollectable memory leak in the traditional sense). |
|
Ok, then in that case would it not make more sense to write to a temporary file and have the browser read that, so that actions such as refreshing don't automatically cause the page to disappear? |
|
Yes, I think that may make more sense. However, when I tried using |
|
I would also prefer a temp file over trying to launch a web server, which is fraught with more issues than is immediately apparent. I'd also prefer to see a valid HTML5 document--add a |
|
@embray how's that? FYI, I only used the WebServer because I couldn't get |
|
Doesn't https://github.com/astropy/astropy/blob/master/astropy/table/table.py#L1368 |
|
Oops, yes. Thanks @mdboom, removing... |
|
I see -- so the return trick works by virtue of the fact that you're probably running this at a console, and taking advantage of the fact that it stores a history of results. That's probably fine in IPython where it stores a lot of history (that I always find hard to get rid of), but at the standard Python console, it's not so great: Personally, I don't mind so much if "refresh" doesn't work, but I thought I'd point it out. It also doesn't work in a script, which I think is more serious. I know it seems odd, but people may want to have scripts that generate a complicated table and then pop up the results in a browser and maybe a plot in another window. Maybe we need to delete the tempfile in a |
|
Good question. One option is to state that, for persistent/script use, you need to do The options seem to be:
I prefer 1 because it's cleaner and easier, but not strongly. |
|
These last two commits may fall under an entirely different category... but I just added a little javascript so that the table is sortable & searchable within the browser. I could go on forever, making it nicely formatted, colored, etc, which is probably a dumb idea, but I think the sortable table is a useful feature. Note that if you run this offline, i.e. without an internet connection, it will just display the dumb pure-html table as normal. |
|
Very cool use of javascript. Maybe it would be better to add that feature as part of |
|
That's a good idea; I'll split out the javascript viewer into a different function in the |
|
@mdboom - ipython does not like the js used for this viewer, I get very odd behavior when I invoke the |
|
There's the added issue with |
|
Indeed. I can confirm the weirdness. Something about the initialization isn't right -- by the time the callback gets called, it doesn't get have the DOM content of the table. Probably need to hook into a different javascript callback other than |
|
Right, thanks. I've decided there may be a more sensible way to do this: default repr is the same as old repr, but add a button to turn any table browseable. That deals with the callback issue. |
|
So I got pretty close: this version creates a button that, in principle, converts the simple html table to a complete javascript viewey table. Problems:
|
|
Thanks Jake. It is a bit tricky right now, but I'm 95% of the way there, I think. In principle, the hard part is done.... ...that said, can you point me to any current docs on |
|
(it would be really cool to have a working demo, then move over to bigger & better things when a real API is available) |
|
Try this in a notebook: The (use commit keflavich@a8bf772) |
|
@mdboom Upon further consideration, I really don't think it makes sense to load the jsviewer by default with which I think would be best, though perhaps you'd want to avoid cluttering the namespace. And I don't really know how to call the jsfunction that is added to the html via this method. |
|
Also I've broken lots of tests and this code needs lots of tests. Perhaps the js utilities were too ambitious; those should perhaps be split into a different PR or different module entirely. |
|
and THIS rebase seems to have worked... |
|
That looks better. It seems like unrelated commits seem to |
|
Sorry about the accidental close. What did you do differently the second time around? We've seen these unrelated commits happening before and it's not always clear why. |
|
I have no idea. It might be something as simple as rebasing... I thought I had to rebase twice, but apparently not. According to bash, my command history was: |
|
@keflavich - it looks like there is a test failure? |
|
@eteq @mdboom @taldcroft - does this look ready to merge? It would be cool to get in 0.3.0 so that it gets some user testing. |
|
Looks good to me. I'd rather see the jquery stuff in a central location in case we use it outside of table in the future, but we can cross that bridge when we get there. |
|
Fine by me. |
|
@keflavich - good to go? or was there anything else you wanted to add? |
|
I think it's good to go. |
|
Looks good to go except for one minor thing: It would be nice to adjust the commit tree so that the adding of the minified js goes in the same place the origin adding of the js goes. Then if anyone for some reason wants to checkout an intermediate commit, it will still work. That's totally minor, though, so if you're worried about the rebase on that, it's fine as-is. |
|
So... You want more Stalinization (history editing) or just rebase commit |
|
@eteq - I don't think that's too important, and the issue is that the filename is different. I don't think we ever require branches to be functional until finally merged, right? |
|
I agree with @astrofrog, as long as the end product works and there isn't too much commit noise along the way, then why bother. I think it's fair to say that most PR's cannot be checked out midway and still work. |
|
Agreed. And for things like |
|
I hadn't thought about |
|
Ok so... shall we merge? :) |
|
As a matter of principal, I still think it's worthwhile to have the intermediate commits work when possible - when doing more complicated merge/rebase operations, I've been burned before by this, as it's hard to tell exactly what in your merge broke the other branch's work. But in this case, I now see @astrofrog's point that the filename is different, so it doesn't matter anyway. So I'll merge this as-is. Thanks @keflavich! (and +1 to the term "Stalinization" :) |
Add a "show_in_browser" feature for tables

Tables have a
.pformatcommand that can create html output. This tool uses the output of that command to generate a table and display it in a browser. I think this is a convenient way to view the complete content of tables that are too large to view via, e.g.,pprint.