Skip to content

Commit ee58c9c

Browse files
authored
Fix nbconvert template (#160)
http://b/170301227
1 parent d0bd252 commit ee58c9c

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ ADD install_iR.R /tmp/install_iR.R
7272
ADD bioconductor_installs.R /tmp/bioconductor_installs.R
7373
ADD package_installs.R /tmp/package_installs.R
7474
ADD nbconvert-extensions.tpl /opt/kaggle/nbconvert-extensions.tpl
75+
ADD kaggle/template_conf.json /opt/kaggle/conf.json
7576
# Install with `--vanilla` flag to avoid conflict. https://support.bioconductor.org/p/57187/
7677
RUN Rscript --vanilla /tmp/package_installs.R
7778
RUN Rscript --vanilla /tmp/bioconductor_installs.R

kaggle/template_conf.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"base_template": "classic",
3+
"mimetypes": {
4+
"text/html": true
5+
},
6+
"preprocessors": {
7+
"100-pygments": {
8+
"type": "nbconvert.preprocessors.CSSHTMLHeaderPreprocessor",
9+
"enabled": true,
10+
"style": "default"
11+
}
12+
}
13+
}

nbconvert-extensions.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All cell metadata starting with '_kg_' will be included with its value ({key}-{v
44
as a class in the cell's DIV container
55
#}
66

7-
{% extends 'full.tpl'%}
7+
{% extends 'classic/index.html.j2'%}
88
{% block any_cell %}
99
<div class="{% for k in cell['metadata'] if k.startswith("_kg_") %}{{k}}-{{cell['metadata'][k] | lower}} {% endfor %}">
1010
{{ super() }}

tests/test_nbconvert.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
context("nbconvert")
22

3-
test_that("nbconvert exists", {
3+
test_that("nbconvert to notebook", {
44
expect_error({
55
library(jsonlite)
66

@@ -10,3 +10,11 @@ test_that("nbconvert exists", {
1010
expect_equal(json$cells[[1]]$outputs[[1]]$text[[1]], "[1] 999\n")
1111
}, NA) # expect no error to be thrown
1212
})
13+
14+
test_that("nbconvert to html", {
15+
expect_error({
16+
results <- system("jupyter nbconvert --to html --stdout --template /opt/kaggle/nbconvert-extensions.tpl --Exporter.preprocessors=[\\\"nbconvert.preprocessors.ExtractOutputPreprocessor\\\"] \"/input/tests/data/notebook.ipynb\"",
17+
intern = TRUE)
18+
expect_match(toString(results), ".*>999<.*") # [...] <span class="n">x</span> <span class="o">&lt;-</span> <span class="m">999</span> [...]
19+
}, NA) # expect no error to be thrown
20+
})

0 commit comments

Comments
 (0)