Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Data Visualization Example with lets-plot does not work. #154

Open
muthenberg opened this issue Aug 25, 2022 · 6 comments
Open

Data Visualization Example with lets-plot does not work. #154

muthenberg opened this issue Aug 25, 2022 · 6 comments

Comments

@muthenberg
Copy link

Hi,

I would like to do some data visualization using krangl and lets-plot. I tried to get the example working. For this I created a new jupyter-lab notebook with a single section containing the following code from the example:

%use krangl(0.17)
%use lets-plot

var sleepDataExt = sleepData.addColumn("rem_proportion"){it["sleep_rem"]/it["sleep_total"]}
sleepDataExt.letsPlot {x="sleep_total"; y="rem_proportion" } + geomPoint()

Upon execution I get an error message stating: Line_58.jupyter-kts (5:64 - 75) Type mismatch: inferred type is geomPoint but Feature was expected

Did I do something wrong? Is this a known bug? Is there a workaround?

Thanks and regards

@holgerbrandl
Copy link
Owner

Please use the latest version 0.18.2. For me this seems to work, could you confirm?

@muthenberg
Copy link
Author

muthenberg commented Aug 29, 2022

I changed the Code to:

%use krangl(0.18.4)
%use lets-plot

var sleepDataExt = sleepData.addColumn("rem_proportion"){it["sleep_rem"]/it["sleep_total"]}
sleepDataExt.letsPlot {x="sleep_total"; y="rem_proportion" } + geomPoint()

But I still get:

Line_69.jupyter-kts (4:64 - 75) Type mismatch: inferred type is geomPoint but Feature was expected

On the terminal where my Jupyter-Lab is running I get the following output related to this error message. Is this of any use to you?

334831555 [main] DEBUG SocketWrapper - [SHELL] snd>: msg[f92e6a1e-84bb-45dd-bf52-e446681faeae] 
{
  "header": {
    "msg_id": "42739e09-1c8c-4632-81d4-f1f28c5a3cf4",
    "msg_type": "execute_reply",
    "session": "f92e6a1e-84bb-45dd-bf52-e446681faeae",
    "username": "",
    "version": "5.3",
    "date": "2022-08-29T10:58+0200"
  },
  "parent_header": {
    "msg_id": "e0382a18-f211-439f-9fc3-88c199dc4c92",
    "msg_type": "execute_request",
    "session": "f92e6a1e-84bb-45dd-bf52-e446681faeae",
    "username": "",
    "version": "5.2",
    "date": "2022-08-29T08:58:08.204Z"
  },
  "metadata": null,
  "content": {
    "status": "error",
    "execution_count": 12,
    "ename": "org.jetbrains.kotlinx.jupyter.exceptions.ReplCompilerException",
    "evalue": "Line_69.jupyter-kts (4:64 - 75) Type mismatch: inferred type is geomPoint but Feature was expected",
    "traceback": [
      "org.jetbrains.kotlinx.jupyter.repl.impl.JupyterCompilerImpl.compileSync(JupyterCompilerImpl.kt:174)",
      "org.jetbrains.kotlinx.jupyter.repl.impl.InternalEvaluatorImpl.eval(InternalEvaluatorImpl.kt:99)",
      "org.jetbrains.kotlinx.jupyter.repl.impl.CellExecutorImpl$execute$1$result$1.invoke(CellExecutorImpl.kt:71)",
      "org.jetbrains.kotlinx.jupyter.repl.impl.CellExecutorImpl$execute$1$result$1.invoke(CellExecutorImpl.kt:69)",
      "org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl.withHost(repl.kt:635)",
      "org.jetbrains.kotlinx.jupyter.repl.impl.CellExecutorImpl.execute(CellExecutorImpl.kt:69)",
      "org.jetbrains.kotlinx.jupyter.repl.CellExecutor$DefaultImpls.execute$default(CellExecutor.kt:15)",
      "org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl$evalEx$1.invoke(repl.kt:444)",
      "org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl$evalEx$1.invoke(repl.kt:433)",
      "org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl.withEvalContext(repl.kt:397)",
      "org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl.evalEx(repl.kt:433)",
      "org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl.eval(repl.kt:485)",
      "org.jetbrains.kotlinx.jupyter.messaging.ProtocolKt$shellMessagesHandler$2$res$1.invoke(protocol.kt:321)",
      "org.jetbrains.kotlinx.jupyter.messaging.ProtocolKt$shellMessagesHandler$2$res$1.invoke(protocol.kt:320)",
      "org.jetbrains.kotlinx.jupyter.JupyterExecutorImpl$runExecution$execThread$1.invoke(execution.kt:33)",
      "org.jetbrains.kotlinx.jupyter.JupyterExecutorImpl$runExecution$execThread$1.invoke(execution.kt:31)",
      "kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)"
    ],
    "additionalInfo": {
      "lineStart": 4,
      "colStart": 64,
      "lineEnd": 4,
      "colEnd": 75,
      "message": "Type mismatch: inferred type is geomPoint but Feature was expected",
      "path": "Line_69.jupyter-kts"
    }
  }
}

@alshan
Copy link

alshan commented Aug 30, 2022

As geomPoint does of course extend Feature, the failure

Type mismatch: inferred type is geomPoint but Feature was expected

was likely caused by class loading conflict I reported here: #143

As a workaround: any usage of Lets-Plot before any usage of Krangl API will secure loading of Lets-Plot classes from correct jars.
I usually just insert LetsPlot.getInfo() just after %use lets-plot.
For example: https://nbviewer.org/github/JetBrains/lets-plot-kotlin/blob/master/docs/examples/jupyter-notebooks/geom_violin.ipynb

@muthenberg
Copy link
Author

If I change to:

%use krangl(0.18.4)
%use lets-plot
LetsPlot.getInfo()

var sleepDataExt = sleepData.addColumn("rem_proportion"){it["sleep_rem"]/it["sleep_total"]}
sleepDataExt.letsPlot {x="sleep_total"; y="rem_proportion" } + geomPoint()

the error unfortunately still persists.

I also tried to load lets plot before krangl:

%use lets-plot
LetsPlot.getInfo()
%use krangl(0.18.4)

var sleepDataExt = sleepData.addColumn("rem_proportion"){it["sleep_rem"]/it["sleep_total"]}
sleepDataExt.letsPlot {x="sleep_total"; y="rem_proportion" } + geomPoint()

This doesn't solve the problem either. :(

@alshan
Copy link

alshan commented Sep 2, 2022

Which Lets-Plot version does LetsPlot.getInfo() report?
I believe that krangl v0.18.4 has already switched to the latest Lets-Plot Kotlin API v4.0.0.

If LetsPlot.getInfo() reports an older version then you need to tell Kotlin kernel to use the latest one. There are two options:

  • Use the %useLatestDescriptors line magic.
  • Provide the required version manually: %use lets-plot(api=4.0.0, lib=2.4.0, js=2.4.0)

Does this help?

@muthenberg
Copy link
Author

Ok. Some of that advice seems to have fixed it. At first I still encountered the problem and needed to reset the kernel. After that it worked. Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants