Skip to content

Commit

Permalink
Jupyter formatting fix (#484)
Browse files Browse the repository at this point in the history
* More formatting fixes to the Jupyter docs

* Add script to run docs locally

* Add alternative local running instructions

* Newline to preempt linting anger
  • Loading branch information
michaeljcollinsuk authored Jan 23, 2025
1 parent c74fc09 commit 9efcaa2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ To preview the guidance locally on an MoJ Digital and Technology MacBook, you wi
make preview
```

If this method does not work, try running the below as an alternative:

```
bash scripts/local.sh
```

You can view the guidance on `http://localhost:4567` in your browser. Any content changes you make to your website will be updated in real time.

To shut down the Middleman instance running on your machine, select ⌘+C.
Expand Down
27 changes: 27 additions & 0 deletions scripts/local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

MODE="${1:-preview}"
TECH_DOCS_PUBLISHER_IMAGE="docker.io/ministryofjustice/tech-docs-github-pages-publisher@sha256:cd3513beca3fcaf5dd34cbe81a33b3ff30337d8ada5869b40a6454c21d6f7684" # v4.0.0

case ${MODE} in
package | preview)
true
;;
*)
echo "Usage: ${0} [package|preview]"
exit 1
;;
esac

if [[ "$(uname -m)" == "aarch64" ]] || [[ "$(uname -m)" == "arm64" ]] && [[ "$(uname)" != "Darwin" ]]; then
PLATFORM_FLAG="--platform=linux/amd64"
else
PLATFORM_FLAG=""
fi

docker run -it --rm ${PLATFORM_FLAG} \
--name "tech-docs-${MODE}" \
--publish 4567:4567 \
--volume "${PWD}/config:/app/config" \
--volume "${PWD}/source:/app/source" \
"${TECH_DOCS_PUBLISHER_IMAGE}" "/usr/local/bin/${MODE}"
1 change: 1 addition & 0 deletions source/documentation/appendix-docs/app_development.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
> **IMPORTANT:**
> These instructions are for older versions of JupyterLab earlier than v3.6.3-4.1.0.
>
> [You can find the latest documentation on running an application locally here](https://user-guidance.analytical-platform.service.justice.gov.uk/tools/jupyterlab/index.html#accessing-a-locally-running-application).

Expand Down
17 changes: 12 additions & 5 deletions source/documentation/tools/jupyterlab/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,29 @@ And then select the kernel in Jupyter as [normal](../tools/package-management.ht

## Accessing a Locally Running Application

As of version JupyterLab v3.6.3-4.1.0, to access an application running locally (such as Dash or Streamlit), it *must* be running on port `8081`. You can then access it by visiting `https://${USERNAME}-jupyter-lab-tunnel.tools.analytical-platform.service.justice.gov.uk`. As apps are only accessible on port 8081, you can only run one app at a time.
As of version `JupyterLab v3.6.3-4.1.0`, to access an application running locally (such as Dash or Streamlit), it **must** be running on port `8081`.

You can then access it by visiting `https://${USERNAME}-jupyter-lab-tunnel.tools.analytical-platform.service.justice.gov.uk`. As apps are only accessible on port 8081, you can only run one app at a time.

This cannot be accessed by anyone other than yourself as it uses the same authentication method as your tooling.

There is no longer a requirement to run your app (e.g. Dash or Steamlit) on a base url path e.g. `/_tunnel_/8050/`. This is only required for older versions of JupyterLab that are now deprecated.
There is no longer a requirement to run your app (e.g. Dash or Steamlit) on a base url path e.g. `/\_tunnel\_/8050/`. This is only required for older versions of JupyterLab that are now deprecated.

### Hints and tips

- To run a Dash app on port `8081` use the `port` arg when using the `app.run` command in your code e.g.:

```
if __name__ == '__main__':
app.run(port=8081)
```
- To run a Streamlit app on port `8081` you can use the `--server.port` flag when running the app e.g.
```
streamlit run app.py --server.port 8081
```
```
streamlit run app.py --server.port 8081
```
Alternatively, set the server port environment variable in your terminal session before running your app `export STREAMLIT_SERVER_PORT=8081`
Expand Down

0 comments on commit 9efcaa2

Please sign in to comment.