diff --git a/build.gradle.kts b/build.gradle.kts
index 2c439c7f..c24d5527 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -10,7 +10,7 @@ val plotlyVersion by extra("2.29.0")
allprojects {
group = "space.kscience"
- version = "0.7.1.1"
+ version = "0.7.1.1-ktor3"
}
apiValidation {
diff --git a/examples/fx-demo/src/main/kotlin/space/kscience/plotly/fx/PlotlyFXController.kt b/examples/fx-demo/src/main/kotlin/space/kscience/plotly/fx/PlotlyFXController.kt
index c0dc21be..da68e11b 100644
--- a/examples/fx-demo/src/main/kotlin/space/kscience/plotly/fx/PlotlyFXController.kt
+++ b/examples/fx-demo/src/main/kotlin/space/kscience/plotly/fx/PlotlyFXController.kt
@@ -3,10 +3,7 @@ package space.kscience.plotly.fx
import io.ktor.server.engine.ApplicationEngine
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleStringProperty
-import kotlinx.coroutines.DelicateCoroutinesApi
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-import kotlinx.coroutines.launch
+import kotlinx.coroutines.*
import tornadofx.*
import java.net.URI
@@ -35,9 +32,9 @@ class PlotlyFXController : Controller() {
val address = SimpleStringProperty()
- fun displayPage(page: String) {
+ fun displayPage(page: String) = runBlocking {
server?.let {
- val connector = it.environment.connectors.first()
+ val connector = it.resolvedConnectors().first()
val uri = URI("http", null, connector.host, connector.port, null, null, null)
address.set("$uri/$page")
}
diff --git a/examples/notebooks/plotlykt-demo.ipynb b/examples/notebooks/plotlykt-demo.ipynb
index c2c502bf..81281f1c 100644
--- a/examples/notebooks/plotlykt-demo.ipynb
+++ b/examples/notebooks/plotlykt-demo.ipynb
@@ -2,36 +2,22 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
"metadata": {},
- "outputs": [],
"source": [
"import space.kscience.plotly.PlotlyIntegration\n",
- "\n",
- "val integration = PlotlyIntegration()\n",
- "\n",
- "USE(integration.getDefinitions(notebook).first())\n",
- "//%use plotly"
- ]
- },
- {
- "cell_type": "code",
- "outputs": [],
- "source": [
- "Plotly.jupyter.notebook()"
+ "USE(PlotlyIntegration())\n",
+ "//@file:CompilerArgs(\"-jvm-target=11\")\n",
+ "//@file:Repository(\"https://repo.kotlin.link\")\n",
+ "//@file:DependsOn(\"space.kscience:plotlykt-jupyter-jvm:0.7.1\")"
],
- "metadata": {
- "collapsed": false
- },
+ "outputs": [],
"execution_count": null
},
{
"cell_type": "code",
- "execution_count": null,
"metadata": {
"tags": []
},
- "outputs": [],
"source": [
"import kotlin.math.*\n",
"\n",
@@ -59,14 +45,74 @@
" }\n",
"\n",
"}"
- ]
+ ],
+ "outputs": [],
+ "execution_count": null
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
+ "source": [
+ "HTML(\n",
+ " \"\"\"\n",
+ "
\n",
+ " debug\n",
+ "
\n",
+ " \"\"\".trimIndent()\n",
+ ")"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
"outputs": [],
- "source": []
+ "execution_count": null
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "HTML(\"\"\"\n",
+ "\n",
+ " \"\"\".trimIndent())"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "code",
+ "source": [],
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "HTML(\"\"\"\n",
+ "\n",
+ "\"\"\")"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "code",
+ "source": [],
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "execution_count": null
}
],
"metadata": {
diff --git a/plotlykt-server/build.gradle.kts b/plotlykt-server/build.gradle.kts
index ec7d9cc9..a8c1c210 100644
--- a/plotlykt-server/build.gradle.kts
+++ b/plotlykt-server/build.gradle.kts
@@ -1,5 +1,3 @@
-import space.kscience.gradle.KScienceVersions
-
plugins {
id("space.kscience.gradle.mpp")
kotlin("jupyter.api")
@@ -7,7 +5,7 @@ plugins {
}
val dataforgeVersion: String by rootProject.extra
-val ktorVersion = KScienceVersions.ktorVersion
+val ktorVersion = "3.0.2"
kscience{
jvm()
diff --git a/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServer.kt b/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServer.kt
index d08a057c..7d9a3067 100644
--- a/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServer.kt
+++ b/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServer.kt
@@ -2,6 +2,7 @@ package space.kscience.plotly.server
import io.ktor.http.*
import io.ktor.server.application.*
+import io.ktor.server.cio.CIO
import io.ktor.server.engine.ApplicationEngine
import io.ktor.server.engine.embeddedServer
import io.ktor.server.html.respondHtml
@@ -17,6 +18,7 @@ import io.ktor.websocket.Frame
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.runBlocking
import kotlinx.html.*
import kotlinx.serialization.json.JsonObject
import space.kscience.dataforge.meta.*
@@ -25,7 +27,6 @@ import space.kscience.plotly.*
import space.kscience.plotly.server.PlotlyServer.Companion.DEFAULT_PAGE
import java.awt.Desktop
import java.net.URI
-import kotlin.collections.set
import kotlin.coroutines.CoroutineContext
public enum class PlotlyUpdateMode {
@@ -273,7 +274,7 @@ public fun Application.plotlyModule(route: String = DEFAULT_PAGE, block: PlotlyS
}
// val root: Route = feature(Routing).createRouteFromPath(route)
- return PlotlyServer(plugin(Routing), route).apply(block)
+ return PlotlyServer(plugin(RoutingRoot), route).apply(block)
}
@@ -304,14 +305,14 @@ public fun Plotly.serve(
host: String = "localhost",
port: Int = 7777,
block: PlotlyServer.() -> Unit,
-): ApplicationEngine = scope.embeddedServer(io.ktor.server.cio.CIO, port, host) {
+): ApplicationEngine = scope.embeddedServer(CIO, port, host) {
// install(CallLogging)
install(CORS) {
anyHost()
}
plotlyModule(block = block)
-}.start()
+}.start().engine
/**
* A shortcut to make a single plot at the default page
@@ -328,8 +329,8 @@ public fun PlotlyServer.plot(
}
}
-public fun ApplicationEngine.show() {
- val connector = environment.connectors.first()
+public fun ApplicationEngine.show(): Unit = runBlocking {
+ val connector = resolvedConnectors().first()
val uri = URI("http", null, connector.host, connector.port, null, null, null)
Desktop.getDesktop().browse(uri)
}