@@ -7,6 +7,7 @@ import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData
7
7
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration
8
8
import org.jetbrains.kotlinx.dataframe.io.encodeFrame
9
9
import org.jetbrains.kotlinx.dataframe.io.toHTML
10
+ import org.jetbrains.kotlinx.dataframe.io.toStaticHtml
10
11
import org.jetbrains.kotlinx.dataframe.jupyter.KotlinNotebookPluginUtils.convertToDataFrame
11
12
import org.jetbrains.kotlinx.dataframe.nrow
12
13
import org.jetbrains.kotlinx.dataframe.size
@@ -30,7 +31,7 @@ internal class JupyterHtmlRenderer(
30
31
internal inline fun <reified T : Any > JupyterHtmlRenderer.render (
31
32
noinline getFooter : (T ) -> String ,
32
33
crossinline modifyConfig : T .(DisplayConfiguration ) -> DisplayConfiguration = { it },
33
- applyRowsLimit : Boolean = true
34
+ applyRowsLimit : Boolean = true,
34
35
) = builder.renderWithHost<T > { host, value ->
35
36
val contextRenderer = JupyterCellRenderer (this .notebook, host)
36
37
val reifiedDisplayConfiguration = value.modifyConfig(display)
@@ -44,36 +45,41 @@ internal inline fun <reified T : Any> JupyterHtmlRenderer.render(
44
45
df.nrow
45
46
}
46
47
47
- val html = (
48
- DataFrameHtmlData .tableDefinitions(
49
- includeJs = reifiedDisplayConfiguration.isolatedOutputs,
50
- includeCss = true
51
- ) + df.toHTML(
52
- reifiedDisplayConfiguration,
53
- contextRenderer
48
+ val html = DataFrameHtmlData .tableDefinitions(
49
+ includeJs = reifiedDisplayConfiguration.isolatedOutputs,
50
+ includeCss = true ,
51
+ ).plus(
52
+ df.toHTML(
53
+ configuration = reifiedDisplayConfiguration,
54
+ cellRenderer = contextRenderer,
55
+ includeStatic = false , // is added later to make sure it's put outside of potential iFrames
54
56
) { footer }
55
- ).toJupyterHtmlData()
57
+ ).toJupyterHtmlData()
58
+
59
+ // Generates a static version of the table which can be displayed in GitHub previews etc.
60
+ val staticHtml = df.toStaticHtml(reifiedDisplayConfiguration, DefaultCellRenderer ).toJupyterHtmlData()
56
61
57
62
if (notebook.kernelVersion >= KotlinKernelVersion .from(MIN_KERNEL_VERSION_FOR_NEW_TABLES_UI )!! ) {
58
63
val jsonEncodedDf = json {
59
64
obj(
60
65
" nrow" to df.size.nrow,
61
66
" ncol" to df.size.ncol,
62
67
" columns" to df.columnNames(),
63
- " kotlin_dataframe" to encodeFrame(df.rows().take(limit).toDataFrame())
68
+ " kotlin_dataframe" to encodeFrame(df.rows().take(limit).toDataFrame()),
64
69
)
65
70
}.toJsonString()
66
- notebook.renderAsIFrameAsNeeded(html, jsonEncodedDf)
71
+ notebook.renderAsIFrameAsNeeded(html, staticHtml, jsonEncodedDf)
67
72
} else {
68
73
notebook.renderHtmlAsIFrameIfNeeded(html)
69
74
}
70
75
}
71
76
72
- internal fun Notebook.renderAsIFrameAsNeeded (data : HtmlData , jsonEncodedDf : String ): MimeTypedResult {
77
+ internal fun Notebook.renderAsIFrameAsNeeded (data : HtmlData , staticData : HtmlData , jsonEncodedDf : String ): MimeTypedResult {
73
78
val textHtml = if (jupyterClientType == JupyterClientType .KOTLIN_NOTEBOOK ) {
74
- data.generateIframePlaneText(currentColorScheme)
79
+ data.generateIframePlaneText(currentColorScheme) +
80
+ staticData.toString(currentColorScheme)
75
81
} else {
76
- data.toString(currentColorScheme)
82
+ ( data + staticData) .toString(currentColorScheme)
77
83
}
78
84
79
85
return mimeResult(
0 commit comments