tablesaw icon indicating copy to clipboard operation
tablesaw copied to clipboard

Embedded graphs in Jupyter Notebook.

Open garretwilson opened this issue 5 years ago • 13 comments

My mind is blown. I just installed Anaconda and Jupyter Notebook, then I installed the IPython kernel, and then I used tablesaw to load the tornadoes test data file and generate a graph!! Keep in mind that I haven't used Jupyter Notebook at all before, so I'm impressed that it was this easy so far.

Tablesaw opened the graph in a new browser tab, as might be expected. Is there something simple I can do to get the graphs to embed right in Jupyter Notebook, sort of like this?

IJava embedded graph

Now that I've asked the question, I realize that in your readme (sorry for not looking there first) you recommend something called BeakerX. But seeing as that I already have Anaconda+Jupyter+IJava already working, maybe someone has a tip to go straight for the embedded graphs.

Looking cool, people! This has a lot of potential…

garretwilson avatar Feb 07 '19 22:02 garretwilson

Thanks.

The Plot class controls the output. Idk Jupiter so idk how to direct the output there. Maybe Ben has an idea.

On Thu, Feb 7, 2019 at 5:21 PM Garret Wilson [email protected] wrote:

My mind is blown. I just installed Anaconda and Jupyter Notebook, then I installed the IPython kernel, and then I used tablesaw to load the tornadoes test data file and generate a graph!! Keep in mind that I haven't used Jupyter Notebook at all before, so I'm impressed that it was this easy so far.

Tablesaw opened the graph in a new browser tab, as might be expected. Is there something simple I can do to get the graphs to embed right in Jupyter Notebook, sort of like this?

[image: IJava embedded graph] https://raw.githubusercontent.com/SpencerPark/IJava/master/docs/img/display-img.png

Now that I've asked the question, I realize that in your readme (sorry for not looking there first) you recommend something called BeakerX. But seeing as that I already have Anaconda+Jupyter+IJava already working, maybe someone has a tip to go straight for the embedded graphs.

Looking cool, people! This has a lot of potential…

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jtablesaw/tablesaw/issues/461, or mute the thread https://github.com/notifications/unsubscribe-auth/ADRXgk9QpveH7NDqigXhHkQjMJzDdyUQks5vLKbcgaJpZM4aqRDQ .

lwhite1 avatar Feb 07 '19 22:02 lwhite1

I've never used the IJava kernel. Here's an example with the BeakerX kernel: https://nbviewer.jupyter.org/github/benmccann/nbviewer-test/blob/master/Tablesaw.ipynb

benmccann avatar Feb 07 '19 23:02 benmccann

Since the objective of my question was to embed graphs, I scrolled down the BeakerX example until I found some graphs. But the code before each one appears to be Python. (Maybe I'm not understanding exactly what is going on in those examples, because there seems to be Python code mixed with Java code.) Has anyone anywhere ever embedded a Tablesaw Plotly graph in any Jupyter Notebook Java kernel?

garretwilson avatar Feb 08 '19 03:02 garretwilson

It's not Python. It's Groovy. You could write that code in Java as well since Java and Groovy are compatible. You'd just need to convert the syntax to Java

The reason I wrote the example in Groovy originally was that Groovy makes it easier to share variables across cells in Jupyter. I'm primarily a Java developer, but found the Groovy syntax close enough that it was easier to use Groovy than deal with sharing variables across cells in Java, which wasn't as user-friendly. There's a chance that decision should be revisited now that Java 9 is out with JShell

benmccann avatar Feb 08 '19 03:02 benmccann

See https://github.com/twosigma/beakerx/issues/5428 to track JShell support

benmccann avatar Feb 08 '19 08:02 benmccann

@garretwilson Have you had any success redirecting the plots in Jupyter without beakerX?

@benmccann I never really paid any attention to your BeakerX example because I don't use jupyter, but it's wonderful.

lwhite1 avatar Feb 17 '19 16:02 lwhite1

Guys, I got in touch with @SpencerPark over at https://github.com/SpencerPark/IJava/, and in https://github.com/SpencerPark/IJava/issues/49 he outlined exactly what needs to be done. The result is astounding! Tablesaw interactive graphs appear right in Jupyter! Perhaps that is what you were doing already with BeakerX, but this is a thin, pure Java kernel with the very latest Java release (I'm using OpenJDK 11). This opens up so many possibilities!!

Should we consider adding the thin "enabler" code for IJava from https://github.com/SpencerPark/IJava/issues/49 ? Glancing at your BeakerX example, I imagine it would be doing something like this in IJava:

%maven tech.tablesaw:tablesaw-ijava:0.31.0
tech.tablesaw.ijava.TablesawRendeer.register()

That's just the general idea; I'll look at the IJava code more in detail to get the naming just right.

Would you like me to go ahead and create something like this? If so, do you prefer that I first fork the repository and then make a pull request from that?

garretwilson avatar Feb 21 '19 00:02 garretwilson

@garretwilson That's awesome.

I'm inclined to defer to @benmccann on Jupyter-related work. In general, we ask people who want to contribute to follow the contribution guidelines. You can find them here.

https://jtablesaw.github.io/tablesaw/contributing

Thanks for following up on this.

lwhite1 avatar Feb 21 '19 01:02 lwhite1

What might be interesting would be to first render https://nbviewer.jupyter.org/github/benmccann/nbviewer-test/blob/master/Tablesaw.ipynb with IJava and see what the differences are. That might help us better understand how the two kernels compare. And if we decide we want to promote IJava usage with Tablesaw, then we'd have a good example to use for documentation

benmccann avatar Feb 21 '19 03:02 benmccann

You did understand I was proposing making a separate sub-project, with a simple enabler for the kernel, right? It would be a separate dependency, and be deployed to Maven Central as a separate artifact. Only people using IJava would use it. So your statement confuses me a bit. I figured that even if there are 25 kernels out there, you wouldn't care how they "compared", you would just want to promote the use of Tablesaw on as many platforms as possible.

That might help us better understand how the two kernels compare.

That's where I'm confused (not cranky). Let's say (hypothetically) that it's a crappy kernel. Even then, is there any reason you wouldn't want the crappy kernel to be supported if someone is wanting to add support for free? Doesn't more platforms equal more Tablesaw popularity across the board?

It's a tiny code snippet; I can publish it in my own library for people to use, but I just thought that it would benefit Tablesaw more if I contributed it to the official distribution. Let me know which you prefer; I want to help out.

garretwilson avatar Feb 21 '19 04:02 garretwilson

What might be interesting would be to first render https://nbviewer.jupyter.org/github/benmccann/nbviewer-test/blob/master/Tablesaw.ipynb with IJava …

But to your point, yeah I think it would be interesting too, and in fact I'll be going through that and most of the online documentation, now that I have an easy platform to try it out on. I just don't want to copy and paste that code every time I start up, so I figured I'd put it in a library, and I'd frankly rather not implement it twice (once in my library and then later in yours) because my time is so limited.

How do you render that live-looking notebook, by the way in the link you mentioned? (Again I'm completely new to Jupyter Notebook.) If I recreate that notebook using IJava, where would I put it?

garretwilson avatar Feb 21 '19 04:02 garretwilson

is there any reason you wouldn't want the crappy kernel to be supported

I'd never be against an integration supporting Tablesaw. The question that I'd want to consider a bit more closely is about doing it in your own repo vs the Tablesaw repo. If it's in the Tablesaw repo then we're signing up to support the integration long term, which means doing code review on patches, keeping it working on newer versions of the kernel, answering user questions about it, etc.

How do you render that live-looking notebook, by the way in the link you mentioned?

Check a notebook into a git repo or gist. Make sure to save widget state in Jupyter before checking it in. Paste the link into https://nbviewer.jupyter.org/

benmccann avatar Feb 21 '19 05:02 benmccann

Interested in getting some nice(R) graphs in my iJava notebooks too. Did this go anywhere?

bsbodden avatar May 13 '23 19:05 bsbodden