Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mnt/vitest #676

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions apps/simple/static/paths.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<html>
<head>
<title>Jupyter - Thebe Demo</title>
<!-- Configure and load Thebe !-->
<script type="text/x-thebe-config">
{
requestKernel: true,
mountActivateWidget: true,
mountStatusWidget: true,
useJupyterLite: false,
useBinder: false,
serverSettings: {
baseUrl: 'http://localhost:8888',
token: 'test-secret'
},
kernelOptions: {
path: '/notebooks'
}
}
</script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<link rel="stylesheet" href="thebe.css" />
<link rel="stylesheet" href="main.css" />
<script src="index.js"></script>
<style>
.CodeMirror {
max-width: 900px;
}
pre.code {
background-color: #eee;
padding: 16px;
}
</style>
</head>
<body>
<div style="margin: 24px auto; max-width: 900px">
<h1>Executing cells in context of the crrect notebook path</h1>
<p>
Even though thebe works with individual cells, it still executes them in the context of the
a session. Sessions pair an individual kernel with a notebook context that requires a notebook's location
to be specified. As no notebook exists this can see suplerflous but it is still required in order
to propoerly execute code that is dependent on relative paths.
</p>
<p>
Consider a jupyter server started in a root folder, which in turn contains a folder called <code>notebooks</code>.
<code>ipynb</code> files are located in the <code>notebooks</code> folder and are developed with
paths suitable for locaing a data file in a <code>data</code> folder located in the same folder as the notebook.
Without the path being correctly set to the notebook's location, the code will fail to execute.
</p>
<p>
To use this demo you will need to start a local jupyter folder in a root folder with the following structure:
<pre>
.
-- notebooks/
-- screening.ipynb
-- data/
-- data.csv
</pre>
The file <code>data.csv</code> can contain anything and the notebook should simply include the following python code:

<pre>
with open('data/data.csv', 'r') as f:
print(f.read())
</pre>
<p>

to to have a juptyer server available and able to receive connections
from <code>localhost</code>. To start a local server, use the following command:
</p>
<p>
<code>jupyter lab --NotebookApp.token=test-secret --NotebookApp.allow_origin='*'</code>
</p>
<div class="thebe-activate"></div>
<div class="thebe-status"></div>
<pre
style="background-color: #eee; padding: 16px"
data-executable="true"
data-language="python"
>
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('data/data.csv')
df.head()
</pre>
</div>
</body>
</html>
Loading
Loading