Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.09k stars 106 forks source link

Using host.display inside Renderer leads to strange behavior #431

Closed koperagen closed 9 months ago

koperagen commented 9 months ago

I have a renderer created using this api: org/jetbrains/kotlinx/jupyter/api/renderersHandling.kt:224

USE {
    addRenderer(createRenderer({ it.value is Int }, { host, value -> host.display("hi from host.display", null)  }))
}

Apparently in this API i should return "rendered" value as a lambda result, so my usage of API is wrong. But results are still quite unexpected: image

koperagen commented 9 months ago

Hm, i think i stumbled upon a renderer that actually needs API that allows host.display calls (or some other way to render something two times)

USE {
    val kType = typeOf<Pair<AnyFrame, AnyFrame>>()
    addRenderer(createRenderer({ it.isOfCompileTimeType(kType) }, { host, property ->
        val value = property.value
        value as Pair<AnyFrame, AnyFrame>
        host.display(value.first, null)
        host.display(value.second, null)
    }))
}
ileasile commented 9 months ago

@koperagen I fixed this problem, thank you for reporting