SciProgCentre / plotly.kt

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

Webview in JavaFx demo is blank #69

Closed bjonnh closed 3 years ago

bjonnh commented 3 years ago

Curiously the webview is blank it is the same in my application. If I connect to http://localhost:7777/Static or /Dynamic with a webbrowser it works perfectly and it even react to the scale slider in the Dynamic demo.

If I load a random webpage with plotly on it inside WebView (https://chart-studio.plotly.com/create/?fid=plotly2_demo:4#/) , it works, so WebView is working properly and javascript in it as well.

Using JavaFX 15 on Linux (Wayland).

I looked at the onerror/onalert, but nothing showed up.

I tested with your main branch only.

The dev branch fails with

> Task :fx-demo:run FAILED
Error: Could not find or load main class kscience.plotly.fx.PlotlyFXAppKt
Caused by: java.lang.ClassNotFoundException: kscience.plotly.fx.PlotlyFXAppKt
bjonnh commented 3 years ago

In the dev branch, I updated the fx-demo/build.gradle.kts

with

application {
    mainClassName = "space.kscience.plotly.fx.PlotlyFXAppKt"
}

as you changed the names, and changed the javafx version to 15, but it behaves exactly the same.

altavir commented 3 years ago

I just tried it from the latest dev build (and thank you, I had to fix entry points): https://github.com/mipt-npm/plotly.kt/commit/e3f8978051ea9fa080492f102a4ce630032380d7. It is working as expected. Could you try the dev build (clone and gradlew :fx-demo:run). Maybe JS bundle deploy failed in intermediate versions. I tshould work fin in the new release.

I am also thinking about moving to CEF implementation and Compose-Desktop. But I do not have time for it right now.

bjonnh commented 3 years ago

I tried the dev build it does exactly the same thing. I think all the back end works properly, it is really something in webview that is not working. What Java/JavaFX version and platform are you using?

I'm surprised webview works with all the websites I tested but fails with this. And other browsers have absolutely no issue displaying it.

I may try compose-desktop but that would mean porting all of my application from JavaFX to that (not that it is big)…

bjonnh commented 3 years ago

Interestingly it works with Java11… The 11 and 15 are from the same source (ArchLinux packages).

altavir commented 3 years ago

I've reproduced the problem on liberica-15. I'll look into it.

altavir commented 3 years ago

Interesting. It seems to be a Ktor bug.

17:24:26.967 [DefaultDispatcher-worker-2 @request-handler#28] ERROR ktor.application - Unhandled: GET - /
java.lang.NullPointerException: jarEntry must not be null
    at io.ktor.http.content.JarFileContent.<init>(JarFileContent.kt:41)
    at io.ktor.http.content.StaticContentResolutionKt.resourceClasspathResource(StaticContentResolution.kt:62)
    at io.ktor.http.content.StaticContentResolutionKt.resolveResource(StaticContentResolution.kt:38)
    at io.ktor.http.content.StaticContentResolutionKt.resolveResource$default(StaticContentResolution.kt:24)
    at io.ktor.http.content.StaticContentKt$resources$1.invokeSuspend(StaticContent.kt:230)
    at io.ktor.http.content.StaticContentKt$resources$1.invoke(StaticContent.kt)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:246)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:116)
    at io.ktor.util.pipeline.SuspendFunctionGun.execute(SuspendFunctionGun.kt:136)
    at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:79)
    at io.ktor.routing.Routing.executeResult(Routing.kt:155)
    at io.ktor.routing.Routing.interceptor(Routing.kt:39)
    at io.ktor.routing.Routing$Feature$install$1.invokeSuspend(Routing.kt:107)
    at io.ktor.routing.Routing$Feature$install$1.invoke(Routing.kt)
    at io.ktor.util.pipeline.DebugPipelineContext.proceedLoop(DebugPipelineContext.kt:82)
    at io.ktor.util.pipeline.DebugPipelineContext.proceed(DebugPipelineContext.kt:60)
    at io.ktor.util.pipeline.DebugPipelineContext.execute(DebugPipelineContext.kt:66)
    at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:79)
    at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invokeSuspend(DefaultEnginePipeline.kt:124)
    at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invoke(DefaultEnginePipeline.kt)
    at io.ktor.util.pipeline.DebugPipelineContext.proceedLoop(DebugPipelineContext.kt:82)
    at io.ktor.util.pipeline.DebugPipelineContext.proceed(DebugPipelineContext.kt:60)
    at io.ktor.util.pipeline.DebugPipelineContext.execute(DebugPipelineContext.kt:66)
    at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:79)
    at io.ktor.server.cio.CIOApplicationEngine$handleRequest$2.invokeSuspend(CIOApplicationEngine.kt:189)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
bjonnh commented 3 years ago

I do not see that error, maybe there is no logging by default?

altavir commented 3 years ago

Yes, I switched to different logging in DataForge and now logback is not provided by default. One needs to add implementation("ch.qos.logback:logback-classic:1.2.3") to dependencies for logs to work. I fixed the problem with ktor, but I still can't see the picture on JDK 15.

altavir commented 3 years ago

@bjonnh I've localized the problem. It is the crappy FX-browser again. The problem is that plotly JS is rather large and it takes some time to load it. And FX browser does not process the loading event properly for some reason. I will try to find a workaround for that.

bjonnh commented 3 years ago

Ok let me have a look at how it is handled, I may be able to help with that.

altavir commented 3 years ago

I've just pushed the commit with all logging attached. Toggling back-forward button on the plotly windows makes it display the plot properly, but in general load worker is just stuck on RUNNING

bjonnh commented 3 years ago

(If you did read what I wrote before deleting, that's because I ran directly from IntelliJ not the gradle task)

bjonnh commented 3 years ago

I see where the problem is, you really need to have a function that waits on Plotly to be loaded because order of loading/running scripts is never guaranteed.

altavir commented 3 years ago

I see. It is fixed in the more advanced VisionForge implementation. Probably I will just back-port it to Plotly.

bjonnh commented 3 years ago

But that's pretty clearly unexpected from JavaFX Webview. It should probably behave like other browsers. You can try sending a bug-report to the JavaFX team, but I was never successful at doing that.

bjonnh commented 3 years ago

There is something really weird, if I take a page served by the ktor server, it fails. If I take the html put it on a webserver and load it there, it works see: https://www.bjonnh.net/share/test_static.html

altavir commented 3 years ago

Yes, I had some weird bugs with FX-browser. Sadly it lives in its own world sometimes. I will back-port the solution from VisionForge. It uses Kotlin JS bundling thus solving the loading order problem. As soon as VisionForge is more stable, I will just deprecate server support in plotly.kt. VisionForge is much more powerful anyway (and it already works well with plotly.kt).

bjonnh commented 3 years ago

Once I tell it to not load PlotlyConnect, it works fine.

bjonnh commented 3 years ago

Do you have a demo on how to have simple plots in VisionForge with JavaFX?

bjonnh commented 3 years ago

This makes little sense to me, plotlyConnect.js is just defining functions…

bjonnh commented 3 years ago

From what I see when logging with Ktor, it doesn't even try to load the JS…

altavir commented 3 years ago

Indeed. For some reason, it randomly loads the first scripts and forgets to load the other one or does not load anything at all. When I searched for a fix, people proposed to store the webEngine in a static variable because it gets GCed. But I tried that and it does not help. I will do both Plotly backport and the VisionForge demo in a few days.

altavir commented 3 years ago

@bjonnh I've implemented the back-port, but it did not help. The problem is not the loading order, but just a bugged loader after all. Surprisingly, downgrading JavaFX version to 11 helped. So now it works on dev.

altavir commented 3 years ago

Considered it fixed for now. FX version 11 seems to be working fine.