# TensorBoard Example Web App

[View shared example source code on GitHub](https://github.com/dnanexus/dnanexus-example-applets/tree/master/Tutorials/bash/tensorboard-web-app)

TensorBoard is a web application used to visualize and inspect what is going on inside TensorFlow training. To use TensorBoard, the training script in TensorFlow needs to include code that saves specific data to a log directory where TensorBoard can then find the data to display it.

This example uses an example script from the TensorBoard authors. For more guidance on how to use TensorBoard, check out the TensorFlow website ([external link](https://www.tensorflow.org/tensorboard/get_started)).

## Creating the web application

The applet code runs a training script, which is placed in `resources/home/dnanexus/` to make it available in the current working directory of the worker, and then it starts TensorBoard on port 443 (HTTPS).

```shell
# Start the training script and put it into the background,
# so the next line of code will run immediately
python3 mnist_tensorboard_example.py --log_dir LOGS_FOR_TENSORBOARD &

# Run TensorBoard
tensorboard  --logdir LOGS_FOR_TENSORBOARD --host 0.0.0.0 --port 443
```

The training script runs in the background to start TensorBoard immediately, which allows you to see the results while training is still running. This is particularly important for long-running training scripts.

For all web apps, if everything is running without errors (the ideal case), the line of code that starts the server keeps it running forever. The applet stops only when it is terminated. This also means that any lines of code after the server starts are not executed.

As with all web apps, the `dxapp.json` must include `"httpsApp": {"ports":[443], "shared_access": "VIEW"}` to tell the worker to expose port 443.

## Creating an applet on DNAnexus

Build the asset with the libraries first:

```shell
dx build_asset tensorflow_asset
```

Take the record ID it outputs and add it to the `dxapp.json` for the applet.

```json
"runSpec": {
    ...
    "assetDepends": [
    {
      "id": "record-xxxx"
    }
  ]
    ...
}
```

Then build the applet

```shell
dx build -f tensorboard-web-app
dx run tensorboard-web-app
```

Once it starts, you can go to that job's URL based on its job ID, `https://job-xxxx.dnanexus.cloud`, to see the result.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.dnanexus.com/getting-started/developer-tutorials/python/tensorboard-example-web-app.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
