Kotlin/kandy

A bit lost with kandy vs letsplot

CGenie opened this issue · 22 comments

Hello,
I'm just exploring Kotlin notebooks.

I have a simple cell with this code:

val rand = java.util.Random(37)
val data = mapOf (
    "rating" to List(200) { rand.nextGaussian() } + List(200) { rand.nextGaussian() * 1.5 + 1 },
    "cond" to List(200) { "A" } + List(200) { "B" }
)

letsPlot(data) { x = "rating"; fill = "cond" } + ggsize(700, 300) +
        geomDensity(color = "dark_green", alpha = .7) + scaleFillBrewer(type = "seq") +
        theme(panelGridMajorX = "blank")

However, it doesn't render in Kotlin notebook.

From what I see, letsPlot returns org.jetbrains.letsPlot.intern.Plot.

And compared with this (which does render the graphics properly):

plot(data) {
    x("cond"<String>())

    bars {
        // name = "test"
        y("rating"<Double>())
        fillColor("rating") {
            scale = continuous(range=Color.YELLOW..Color.RED)
        }
    }
}

I see it returns org. jetbrains. kotlinx. kandy. ir.Plot.

Is there a way to convert a letsPlot output to a Kandy one to render the graphics properly?

Ah, ok, maybe this one is related: JetBrains/lets-plot-kotlin#244

Hi! To enable the rendering of lets-plot charts, you need to add the line

%use lets-plot

to your notebook.

But I did, here's what my snippet looks like and I don't see the rendered plot:
https://gitlab.com/-/snippets/3728123

Here's a similar notebook for Kandy where the plot is rendered correctly:
https://gitlab.com/-/snippets/3728124

I get 404 on your links.
What is your version of Notebook?

I changed visibility of the snippets, should be working now.

I'm on intellij idea 2024.1.4 with kotlin notebook version 241.17011.79

And also please specify the kernel version (can be found in Kotlin Notebook plugin settings)

Kernel version is 0.12.0-226

BTW, I had to set -jvm-target=11 and JVM target for snippets to 11 because otherwise kandy complained (in plot) that jvm 1.8 runtime conflicts with 11.

Yes Kandy has jvm 11 target, so it's incompatible with 1.8.
Unfortunately I couldn't reproduce the bug yet, but I'll keep looking into it.
And yeah, you asked above, Lets-Plot plots can't be converted to Kandy plots, but Kandy plots can be converted to Lets-Plot ones (via .toLetsPlot() extension).

Lets-Plot charts use web outputs (while Kandy uses native rendering via Swing) - maybe that's the issue, try testing them with the simplest option (e.g. HTML("Simple html text") line). The notebook must have "Trusted" flag enabled to them display them.

Apparently even HTML("...") doesn't render as well.
Screenshot from 2024-07-12 10-59-40

@CGenie
hi!
About:

Apparently even HTML("...") doesn't render as well.

Could you please specify the next information about versions, and I will try to reproduce it:

  • your IDEA version
  • plugins versions
    • org.jetbrains.plugins.kotlin.jupyter,
    • intellij.jupyter

You can get this info by double shift -> type 'About' -> Copy and close
I just check it with Build #IU-241.18034.62, built on June 20, 2024 and it works fine for me

Monosnap default-empty – nte2 ipynb 2024-07-12 14-42-33

@CGenie

I'm on intellij idea 2024.1.4 with kotlin notebook version 241.17011.79

Sorry, I missed that you had mentioned it earlier.
Let me try to reproduce it.

@CGenie
Can I ask you to update the plugins to version: 2024.1.4 Build: 241.18034.62 ?
In this version, everything should work fine. (and plot renders and web outputs work fine)

Monosnap default-empty – nte2 ipynb 2024-07-12 15-28-25

Sure, it's just I'm not quite sure how: the plugins intellij dialog doesn't show any info about new version and https://plugins.jetbrains.com/plugin/16340-kotlin-notebook/versions doesn't mention 241.18034.62 I think

@CGenie
hi again!
thank you for the information about the plugin version!

I could reproduce the issue you mentioned above with your version.

We just published new plugin version for Kotlin Notebook 241.18034.95 with fixes

Monosnap Versions: Kotlin Notebook Plugin for IntelliJ IDEA | JetBrains Marketplace 2024-07-12 23-05-04

Could you please download and install it and restart IDE?
It should work fine now.

Monosnap default-empty – nte2 ipynb 2024-07-12 23-06-14

Hm, I upgraded, restarted the IDE but it still doesn't render for me. I added some tracebacks, maybe some library that I have is outdated?

https://gitlab.com/-/snippets/3728475

Thank you for your very fast responses, this is top notch support :)

hm, that's a bit strange.
As I can see from your snippet at least HTML (web outputs rendering) should already works.

  1. Could you please run a code like this
    HTML("<h1>Header H1</h1>")

and you should see something like this:
Monosnap default-empty – nte2 ipynb 2024-07-13 11-23-55

  1. Also could you please check plugins versions of Kotlin Notebook plugin and Jupyter:
    Monosnap Settings 2024-07-13 11-24-39

Ah, I didn't notice that but the gitlab notebook renders HTML properly, while in Idea I don't see it...

Screenshot from 2024-07-15 05-49-00

Ok, got it.
Could you please specify the plugins versions and operating system?
plugins:

  • Jupyter
  • Kotlin notebook

OK so I downloaded Idea now, it's at version 241.18034.62 and from what I see it renders properly (I'm on Mandriva Linux).

Previously I used system packages (which has the same 241.18034.62 version) and it doesn't render the graphics properly...

https://aur.archlinux.org/packages/intellij-idea-ultimate-edition this is the package I'm using.

ok, thank you for update!
Does it mean that for now everything works and renders fine?

Yes, thank you!