SciProgCentre / plotly.kt

An interactive Kotlin wrapper for plotly visualization tools
https://sciprogcentre.github.io/plotly.kt/
Apache License 2.0
148 stars 21 forks source link

Setup Issue #47

Closed wangtieqiao closed 3 years ago

wangtieqiao commented 3 years ago

I running into some issue with the setup:

  1. Try to use in Jupyter, based on the documentation I red, just copy the plotly.json and plotyly-server.json into my ..../run_kotlin_kernel/libraries folder then kotlin jupyter kernel should load it in. However I checked that it does not show up. (by type :help in my kotlin notebook, can not see those two libraries listed). I can not see any errors

  2. Then I try to set up in my project and hope to get some clue what is going on, here are portion of my build.gradle.kts

plugins {
    java
    kotlin("jvm") version "1.4.0"
//    kotlin("plugin.serialization") version "1.4.0"
}

repositories {
    mavenCentral()
    jcenter()

    // for plotly.kt
    maven("https://dl.bintray.com/mipt-npm/dataforge")
    maven("https://dl.bintray.com/mipt-npm/kscience")
    maven("https://dl.bintray.com/mipt-npm/dev")
    maven("https://kotlin.bintray.com/kotlinx")
    maven("https://dl.bintray.com/kotlin/ktor")
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
    implementation("org.nield:kotlin-statistics:1.2.1")
    implementation("org.apache.commons:commons-collections4:4.4")
    implementation( "org.jetbrains.kotlin:kotlin-reflect:1.4.0" )

    implementation( "org.jetbrains.lets-plot-kotlin:lets-plot-kotlin-api:1.0.0")

    // for json support
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.8")
//    implementation("io.jhdf:jhdf:0.5.8")
    implementation("de.mpicbg.scicomp:krangl:0.13")
//    implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-RC") // JVM dependency

    // for plotly.kt
    implementation("scientifik:plotlykt-core:0.2.0")
    implementation("scientifik:plotlykt-server:0.2.0")

    testImplementation("org.junit.jupiter:junit-jupiter:5.6.0")

}

when I try to build, got following complain

Could not determine the dependencies of task ':jar'.
> Could not resolve all files for configuration ':runtimeClasspath'.
   > Could not find scientifik:plotlykt-core:0.2.0.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/scientifik/plotlykt-core/0.2.0/plotlykt-core-0.2.0.pom
       - https://jcenter.bintray.com/scientifik/plotlykt-core/0.2.0/plotlykt-core-0.2.0.pom
       - https://dl.bintray.com/mipt-npm/dataforge/scientifik/plotlykt-core/0.2.0/plotlykt-core-0.2.0.pom
       - https://dl.bintray.com/mipt-npm/kscience/scientifik/plotlykt-core/0.2.0/plotlykt-core-0.2.0.pom
       - https://dl.bintray.com/mipt-npm/dev/scientifik/plotlykt-core/0.2.0/plotlykt-core-0.2.0.pom
       - https://kotlin.bintray.com/kotlinx/scientifik/plotlykt-core/0.2.0/plotlykt-core-0.2.0.pom
       - https://dl.bintray.com/kotlin/ktor/scientifik/plotlykt-core/0.2.0/plotlykt-core-0.2.0.pom
     Required by:
         project :
   > Could not find scientifik:plotlykt-server:0.2.0.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/scientifik/plotlykt-server/0.2.0/plotlykt-server-0.2.0.pom
       - https://jcenter.bintray.com/scientifik/plotlykt-server/0.2.0/plotlykt-server-0.2.0.pom
       - https://dl.bintray.com/mipt-npm/dataforge/scientifik/plotlykt-server/0.2.0/plotlykt-server-0.2.0.pom
       - https://dl.bintray.com/mipt-npm/kscience/scientifik/plotlykt-server/0.2.0/plotlykt-server-0.2.0.pom
       - https://dl.bintray.com/mipt-npm/dev/scientifik/plotlykt-server/0.2.0/plotlykt-server-0.2.0.pom
       - https://kotlin.bintray.com/kotlinx/scientifik/plotlykt-server/0.2.0/plotlykt-server-0.2.0.pom
       - https://dl.bintray.com/kotlin/ktor/scientifik/plotlykt-server/0.2.0/plotlykt-server-0.2.0.pom
     Required by:
         project :

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

altavir commented 3 years ago

Hi. First of all. The directory for descriptor seems to be wrong. It should be ~/.jupyter_kotlin/libraries/, where ~ is a user home. In future releases, you should be able to use direct file notation like %use plotly@file[/home/user/plotly.json]. It is described here: https://github.com/Kotlin/kotlin-jupyter#supported-libraries. It should be able to work even without file download just, by references master branch on github: %use plotly@url[https://raw.githubusercontent.com/mipt-npm/plotly.kt/master/notebooks/plotly.json]. Does not work right now though, so you will have to find this library directory.

The build against Kotlin 1.4.0 and kotlinx-serialization 1.0.0-rc won't work right now (see #45 ). We will support 1.4.0 starting at next version (0.3.0 since it will break some binary compatibility). Currently the JS target is broken on 1.4 so I will need to wait untill 1.4.20 for it to be fixed. Right now builds against kotlin 1.3.72 and serialization 0.20.0 should work.

Your code does not work because I forgot to fix a mistake in the readme. We changed the package name (should be kscience.plotlykt instead of scientifik) just before the release and it seems that readme holds the old version. I will fix it right away. The package is available on bintray.

altavir commented 3 years ago

After https://github.com/Kotlin/kotlin-jupyter/pull/103. Descriptors should work without local files.

wangtieqiao commented 3 years ago

Thanks for looking into the issue @altavir

  1. I changed build.gradle.kts based on you mentioned fix above and got that build worked.

    
    // implementation("scientifik:plotlykt-core:0.2.0")
    // implementation("scientifik:plotlykt-server:0.2.0")
    
    implementation("kscience.plotlykt:plotlykt-core:0.2.0")
    implementation("kscience.plotlykt:plotlykt-server:0.2.0")
    
  2. for my installation, the libraries dir is uner

    (base) ~/anaconda3/lib/python3.8/site-packages/run_kotlin_kernel/libraries$ ls -l
    total 88
    -rw-rw-r-- 2 tieqiao tieqiao 1079 Aug  5 12:01 dataframe.json
    -rw-rw-r-- 2 tieqiao tieqiao 1507 Aug  5 12:01 deeplearning4j-cuda.json
    -rw-rw-r-- 2 tieqiao tieqiao 1423 Aug  5 12:01 deeplearning4j.json
    -rw-rw-r-- 2 tieqiao tieqiao   61 Aug  5 12:01 default.json
    -rw-rw-r-- 2 tieqiao tieqiao  260 Aug  5 12:01 exposed.json
    -rw-rw-r-- 2 tieqiao tieqiao  414 Aug  5 12:01 fuel.json
    -rw-rw-r-- 2 tieqiao tieqiao  787 Aug  5 12:01 gral.json
    -rw-rw-r-- 2 tieqiao tieqiao  138 Aug  5 12:01 khttp.json
    -rw-rw-r-- 2 tieqiao tieqiao  183 Aug  5 12:01 klaxon.json
    -rw-rw-r-- 2 tieqiao tieqiao  350 Aug  5 12:01 kmath.json
    -rw-rw-r-- 2 tieqiao tieqiao  318 Aug  5 12:01 koma.json
    -rw-rw-r-- 2 tieqiao tieqiao  239 Aug  5 12:01 kotlin-statistics.json
    -rw-rw-r-- 2 tieqiao tieqiao 1311 Aug  5 12:01 krangl.json
    -rw-rw-r-- 2 tieqiao tieqiao  255 Aug  5 12:01 kravis.json
    -rw-rw-r-- 2 tieqiao tieqiao 1006 Aug  5 12:01 lets-plot-dataframe.json
    -rw-rw-r-- 2 tieqiao tieqiao 1375 Aug  5 12:01 lets-plot.json
    -rw-rw-r-- 2 tieqiao tieqiao  161 Aug  5 12:01 mysql.json
    -rw-rw-r-- 2 tieqiao tieqiao  422 Aug  5 12:01 numpy.json
    -rw-rw-r-- 1 tieqiao tieqiao  980 Sep 13 16:31 plotly.json
    -rw-rw-r-- 1 tieqiao tieqiao 1128 Sep 13 16:32 plotly-server.json
    -rw-rw-r-- 2 tieqiao tieqiao  399 Aug  5 12:01 smile.json
    -rw-rw-r-- 2 tieqiao tieqiao 2576 Aug  5 12:01 spark.json
    

and in the dir you mentioned, seems just a cache directory copied over from above dir

~/.jupyter_kotlin$ ls -l */*/*
-rw-rw-r-- 1 tieqiao tieqiao 1010 Sep 13 16:32 cache/libraries/dataframe.json
-rw-rw-r-- 1 tieqiao tieqiao 1374 Sep 13 16:32 cache/libraries/deeplearning4j-cuda.json
-rw-rw-r-- 1 tieqiao tieqiao 1287 Sep 13 16:32 cache/libraries/deeplearning4j.json
-rw-rw-r-- 1 tieqiao tieqiao  115 Sep 13 16:32 cache/libraries/default.json
-rw-rw-r-- 1 tieqiao tieqiao  249 Sep 13 16:32 cache/libraries/exposed.json
-rw-rw-r-- 1 tieqiao tieqiao  383 Sep 13 16:32 cache/libraries/fuel.json
-rw-rw-r-- 1 tieqiao tieqiao  752 Sep 13 16:32 cache/libraries/gral.json
-rw-rw-r-- 1 tieqiao tieqiao  147 Sep 13 16:32 cache/libraries/khttp.json
-rw-rw-r-- 1 tieqiao tieqiao  179 Sep 13 16:32 cache/libraries/klaxon.json
-rw-rw-r-- 1 tieqiao tieqiao  348 Sep 13 16:32 cache/libraries/kmath.json
-rw-rw-r-- 1 tieqiao tieqiao  298 Sep 13 16:32 cache/libraries/koma.json
-rw-rw-r-- 1 tieqiao tieqiao  255 Sep 13 16:32 cache/libraries/kotlin-statistics.json
-rw-rw-r-- 1 tieqiao tieqiao 1280 Sep 13 16:32 cache/libraries/krangl.json
-rw-rw-r-- 1 tieqiao tieqiao  253 Sep 13 16:32 cache/libraries/kravis.json
-rw-rw-r-- 1 tieqiao tieqiao  952 Sep 13 16:32 cache/libraries/lets-plot-dataframe.json
-rw-rw-r-- 1 tieqiao tieqiao 1249 Sep 13 16:32 cache/libraries/lets-plot.json
-rw-rw-r-- 1 tieqiao tieqiao  167 Sep 13 16:32 cache/libraries/mysql.json
-rw-rw-r-- 1 tieqiao tieqiao  403 Sep 13 16:32 cache/libraries/numpy.json
-rw-rw-r-- 1 tieqiao tieqiao  385 Sep 13 16:32 cache/libraries/smile.json
-rw-rw-r-- 1 tieqiao tieqiao 2506 Sep 13 16:32 cache/libraries/spark.json

Anyway, thanks again for the prompt response, I am in process switch from Python to Kotlin (tried switch to Julia a year ago but had to give up due to too many issues), I am very faithful to you guys. Can not wait to see great stuff come along ....

altavir commented 3 years ago

The documentation changed a bit since the last time I looked at it. Current documentation does not have this paragraph about directories. The one in user directory works fine. The one in conda is used only as a template.

We've tried Julia for some time and we have at least one ongoing projects running on it, but I think it is not the way we want to go. Kotlin scientific ecosystem is in its infancy. Jupyter kernel is highly unstable, but it already allows to do amazing things.

You are welcome to join us on kotlin slack #science channel.

altavir commented 3 years ago

Should work now out of the box.