Example: embed an app in a website using the API
Shiny apps are often embedded in other, larger contexts. For example, consider a portal-style webpage that shows a dashboard with components from different sources, including one or more Shiny apps.
In such a case, the standard web interface of ShinyProxy may not be very useful, and a more controlled approach is necessary.
In this example, the ShinyProxy API is used to launch, show, and stop Shiny apps when the user clicks on buttons.
How to run
- Set up a ShinyProxy instance (e.g. by following the 01-standalone-docker-engine example).
- Set up an HTTP server. This is not in the scope of this example, but any server that can serve static web content should do.
- Download the file
index.htmland have the HTTP server host it.
- Access the
index.htmlpage from a web browser
This example assumes
authentication: noneis set. With authentication enabled, the API calls must be done in a different way, depending on the authentication method. In some cases (OpenId, Social), an
Authorizationheader will be required. In other cases (LDAP, Simple), a separate login must be performed by making a POST request to the
When you launch a proxy via the API, you get back a JSON body describing the proxy. This includes its 'endpoints', which are the URLs where you can access the Shiny app's HTTP interface.
If heartbeat is enabled (by default, it is), then the launched proxy will automatically shut down after 1 minute if it is not displayed in the iframe. Use the settings
heartbeat-timeoutto control this behaviour.