> For the complete documentation index, see [llms.txt](https://documentation.dnanexus.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.dnanexus.com/getting-started/developer-tutorials/bash/r-shiny-example-web-app.md).

# R Shiny Example Web App

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

## Creating the web application

Inside the `dxapp.json`, add `"httpsApp": {"ports":[443], "shared_access": "VIEW"}` to tell the worker to expose this port.

R Shiny needs two scripts, `server.R` and `ui.R`. Place them under `resources/home/dnanexus/my_app/`. When a job starts based on this applet, the `resources` directory is copied onto the worker, and since the `~/` path on the worker is `/home/dnanexus`, that means you have `~/my_app` with those two scripts inside.

From the main applet script `code.sh`, start shiny pointing to `~/my_app`, serving its mini-application on port 443.

```shell
main() {
  R -e "shiny::runApp('~/my_app', host='0.0.0.0', port=443)"
}
```

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

## Modifying this example for your own applet

To make your own applet with R Shiny, copy the source code from this example and modify `server.R` and `ui.R` inside `resources/home/dnanexus/my_app`.

### How to rebuild the shiny asset

[View `dxasset.json` file](https://github.com/dnanexus/dnanexus-example-applets/blob/master/Tutorials/bash/shiny-asset/dxasset.json)

To build the asset, run the `dx build_asset` command and pass `shiny-asset`, that is the name of the directory holding `dxasset.json`:

```shell
dx build_asset shiny-asset
```

This outputs a record ID `record-xxxx` that you can then put into the applet's `dxapp.json` in place of the existing one:

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

### Build the applet

Build and run the applet itself:

```shell
dx build -f r-shiny-web-app
dx run r-shiny-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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://documentation.dnanexus.com/getting-started/developer-tutorials/bash/r-shiny-example-web-app.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
