DockerコンテナでJupyterを実行しています。Jupyter内に別のテーマを適用しました。ノートブックを開くと、新しいテーマが表示されます。HTMLとしてダウンロードでき、テーマはまだそこにあります。
ノートブックの準備ができたら、papermill を使用して複数のコピーを実行し、次のコード スニペットを実行して、nbconvert を使用してノートブックを HTML に変換します。私の問題は、現在のテーマを選択せず、デフォルトのテーマを選択することです。
# Disable the ExtractOutput preprocessor. This prevents images embedded on the notebook (ie: plots) from being externally linked
config = {"ExtractOutputPreprocessor": {"enabled": False}}
# Find the HTML (with TOC) exporter
HTMLTOCExporter = nbconvert.exporters.exporter_locator.get_exporter(
"html_toc"
)
exporter = HTMLTOCExporter(config)
# Add a preprocessor to the exporter to remove the notebook cells with the tag 'remove_cell'
cell_remover = TagRemovePreprocessor(
remove_cell_tags={"remove_cell"}, remove_input_tags={"remove_input"}
)
exporter.register_preprocessor(cell_remover, True)
# Generate HTML and write it to a file
html, resources = exporter.from_filename(notebook_path)
with open(html_tmp_path, "w") as f:
f.write(html)
ドキュメントを見たところ、デフォルトのテンプレートは Jupyter Interactive ビューに似ているはずですが、エクスポートされた HTML は jupyter と同じではありません。https://nbconvert.readthedocs.io/en/latest/usage.html#html