@@ -10,6 +10,9 @@ import org.jetbrains.kotlinx.dataframe.size
10
10
import org.jetbrains.kotlinx.jupyter.api.*
11
11
import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
12
12
13
+ /* * Starting from this version, dataframe integration will respond with additional data for rendering in Kotlin Notebooks plugin. */
14
+ private const val MIN_KERNEL_VERSION_FOR_NEW_TABLES_UI = " 0.11.0.311"
15
+
13
16
internal class JupyterHtmlRenderer (
14
17
val display : DisplayConfiguration ,
15
18
val builder : JupyterIntegration .Builder ,
@@ -32,14 +35,6 @@ internal inline fun <reified T : Any> JupyterHtmlRenderer.render(
32
35
df.nrow
33
36
}
34
37
35
- val jsonEncodedDf = json {
36
- obj(
37
- " nrow" to df.size.nrow,
38
- " ncol" to df.size.ncol,
39
- " columns" to df.columnNames(),
40
- " kotlin_dataframe" to encodeFrame(df.rows().take(limit).toDataFrame())
41
- )
42
- }.toJsonString()
43
38
val html = df.toHTML(
44
39
reifiedDisplayConfiguration,
45
40
extraHtml = initHtml(
@@ -50,7 +45,19 @@ internal inline fun <reified T : Any> JupyterHtmlRenderer.render(
50
45
contextRenderer
51
46
) { footer }
52
47
53
- notebook.renderAsIFrameAsNeeded(html, jsonEncodedDf)
48
+ if (notebook.kernelVersion >= KotlinKernelVersion .from(MIN_KERNEL_VERSION_FOR_NEW_TABLES_UI )!! ) {
49
+ val jsonEncodedDf = json {
50
+ obj(
51
+ " nrow" to df.size.nrow,
52
+ " ncol" to df.size.ncol,
53
+ " columns" to df.columnNames(),
54
+ " kotlin_dataframe" to encodeFrame(df.rows().take(limit).toDataFrame())
55
+ )
56
+ }.toJsonString()
57
+ notebook.renderAsIFrameAsNeeded(html, jsonEncodedDf)
58
+ } else {
59
+ notebook.renderHtmlAsIFrameIfNeeded(html)
60
+ }
54
61
}
55
62
56
63
internal fun Notebook.renderAsIFrameAsNeeded (data : HtmlData , jsonEncodedDf : String ): MimeTypedResult {
0 commit comments