Jupyter-notebook
- jupyter-notebook
.ipynbfile is json with fieldscode,commentand field to memorize the execution result ofcodefield content.
The workflow (pseudocode) looks like as following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
json=ReadFileAsJson(ipynb)
renderAsHtml(json)
# User clicks `div` with cells[1].source content
obj=json.cells[1]
if obj.cell_type == "code":
result = (py obj.source)
obj.metadata.ExecuteTime = result.executeTime
obj.metadata.outputs = result.output
obj.execution_count++
update(obj, json)
renderAsHtml(json)
The usual way to display ipynb is to use the jupyter library, which runs a local web server with a web application to automatically display ipynb.
1
2
3
4
5
& py -m venv venv
& .\venv\Scripts\Activate.ps1
pip install jupyter
& jupyter notebook
- to compile ipynb to html without running webserver use
nbconvertlibrary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Param(
[string][Alias('n')]$name
)
if ($name -like "*.html" ){
& npx http-server . -o $name -p 5001
}
elseif ($name -like "*.ipynb") {
& jupyter nbconvert --to html $name
$html = $name.Substring(0, $name.Length - 6) +".html"
& npx http-server . -o $html -p 5001
}
else
{
Write-Host "The only allowed extensions are .html|.ipynb " -ForegroundColor Green
}
This post is licensed under CC BY 4.0 by the author.