mirror of
https://github.com/TeachBooks/manual.git
synced 2026-11-12 22:35:51 +00:00
updates after review Max
This commit is contained in:
parent
fdfee22d20
commit
f0c3306eec
1 changed files with 6 additions and 8 deletions
|
|
@ -3,7 +3,7 @@
|
|||
Our book has been enable to run Python code live in the browser (thanks Max!). This page contains some installation instructions and the other sections show how to use this functionality to create interactive figures and feedback on code
|
||||
|
||||
## Setting up Python live coding
|
||||
To set up the Python live coding you need to add our [own sphinx-thebe extension](https://gitlab.tudelft.nl/interactivetextbooks-citg/extensions/sphinx-thebe) to your book. The original sphinx thebe extension doesn't run smoothly and reliable. Therefore, you need to add some lines to `requirements.txt` and `_config.yml`
|
||||
To set up the Python live coding you need to add our [own sphinx-thebe extension](https://gitlab.tudelft.nl/interactivetextbooks-citg/extensions/sphinx-thebe) to your book. This extensions doesn't rely on a 3rd party like Binder and it supports local python execution and custom features. Therefore, you need to add some lines to `requirements.txt` and `_config.yml`
|
||||
|
||||
For `requirements.txt` add the following lines:
|
||||
```
|
||||
|
|
@ -26,16 +26,15 @@ sphinx:
|
|||
exclude_patterns: ["**/_*.yml", "**/*.md", "**/*.ipynb"]
|
||||
```
|
||||
|
||||
By `launch_buttons` you initiate the {fa}`rocket` --> {guilabel}`Live Code` on the top right corner of every page generated from a `.ipynb` file. The `html_js_files` link calls for some required javascript files. `use_thebe_lite` makes sure you initiate our adapted sphinx thebe extensions. The `exclude_patterns` makes sure you import all files so that they can be called for from your code, except for the files matching the patterns shown.
|
||||
By `launch_buttons` you initiate the {fa}`rocket` --> {guilabel}`Live Code` on the top right corner of every page generated from a `.ipynb` file. The `html_js_files` link calls for some required javascript files. `use_thebe_lite` makes sure you initiate our adapted sphinx thebe extensions. The `exclude_patterns` makes sure you import all files so that they can be accessed from your code, except for the files matching the patterns shown.
|
||||
|
||||
## Instructions: local build
|
||||
|
||||
To test the fuctionality, you have to run a local server, otherwise the interactivity doens't work. So, you cannot just open the `index.html` file any more. This can be done with the following steps:
|
||||
1. build the book by running the shell script `build-book.sh` (type `./build-book.sh true` in the terminal). If you are using Windows you should use the Git Bash terminal. Set this as your default in VS Code, then open it using "New Terminal." If you have not already done so, you will need to allow Git Bash to use your Python libraries by running the command `conda init bash`.Run the shell script from `book/` (not `book/book/`) using `./build-book.sh`. You may notice that `build-book.sh` creates a Python server (`python -m http.server....`) if you include `true` in the command.; this is critical for getting the interactive code pages to work, you cannot just open the index.html file any more.
|
||||
2. Open the book by going to [http://127.0.0.1:8000/](http://127.0.0.1:8000/) in your browser. You may need to reload the page once the rebuild is complete. You can do this on Chrome by right-clicking somewhere on the page, select "Inspect", open the "Network" tab, then reload with `CTRL+R`. Or try `ctrl`+`F5`
|
||||
3. Go to any page that is created from a Jupyter notebook
|
||||
4. In the top right, click "Live Code" in the rocket ship menu item ({fa}`rocket`)
|
||||
5. Once the message "Python interaction ready!" is displayed, you can run all the cells of the notebook!
|
||||
1. build the book by running ` jupyter book build <directory of your book>`. If you are using Windows you should use the Git Bash terminal. Set this as your default in VS Code, then open it using "New Terminal." If you have not already done so, you will need to allow Git Bash to use your Python libraries by running the command `conda init bash`.
|
||||
2. Set up a server by running `python -m http.server 8000`.
|
||||
3. Open the book by going to [http://localhost:8000/](http://localhost:8000/) in your browser. You may need to reload the page once the rebuild is complete. You can do this on Chrome by right-clicking somewhere on the page, select "Inspect", open the "Network" tab, then reload with `CTRL+R`. Or try `ctrl`+`F5`
|
||||
4. Go to any page that is created from a Jupyter notebook
|
||||
|
||||
If you push to main, you can test the interactivity on the book-draft website as well.
|
||||
|
||||
|
|
@ -46,5 +45,4 @@ With the extended functionality of live code, additional cell tags have been dev
|
|||
- `auto-execute-page` automatically starts the thebe live coding functionality whenever the page is opened. This is particularly useful if you're using widgets on a page. At this moment, this tags doesn't work in combination with `thebe-remove-input-init`
|
||||
- `thebe-init` directly starts running this cell as soon as the thebe live coding functionality starts.
|
||||
- `thebe-remove-input-init`, as `thebe-init`, starts the cell directly as soon as the thebe live coding functionality starts. However, the input is not shown to the students (in static and interactive mode). The original `remove-input` tag will not work as it deletes the entire cell, so it can never be executed.
|
||||
- `keep-output` keep the pre-existing output of a cell of which the input is hidden using `remove-input`.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue