Deploying Shiny apps in Watson Machine Learning
Save a Shiny app to a deployment space, then deploy it as an app and make the URL available to users.
Use case for Shiny applications
Data scientists can build and deploy Shiny application dashboards to share access to the application.
For example, if you create an interactive map infographic, you can deploy the app to a server and socialize the link. Users with the link can click to interact with the infographic.
Available scenarios for running Shiny apps
Available scenarios for deploying a Shiny app depend on the type of project where the Shiny app was developed.
All projects
To deploy a Shiny app from any project type, follow one of these scenarios:
- Create and deploy a Shiny asset directly from RStudio by using an R script. Refer to Example script to deploy a Shiny app.
- Wrap the Shiny app code into a code package by using the command line and
cpdctlorcpd-cli. Use the command line to deploy it. Refer to Creating and registering code package assets by using CPDCTL and Deploying Shiny Apps with cpdctl. - Deploy Shiny Apps with curl and REST API.
- Deploy Shiny Apps with the Watson Machine Learning Python client (For deployment details, follow the steps that are listed in this example notebook: Use R Shiny app to create SIR model).
If you want to deploy a Shiny app that was transferred to the deployment space as a code package, you must first define its software specification. Refer to Preparing code packages that contain Shiny apps before deployment.
Projects with deprecated Git integration
To deploy a Shiny app from a project with deprecated Git integration:
- Export the Watson Studio project to a compressed file on your desktop and then import it into a deployment space. The imported package becomes a code package asset in the space. For more information, see:
- Deploy the Shiny app. Refer to Deploying Shiny apps from the deployment space.
If you want to deploy a Shiny app that was transferred to the deployment space as a code package, you must first define its software specification. Refer to Preparing code packages that contain Shiny apps before deployment.
Projects with default Git integration
To deploy a Shiny app from a project with default Git integration:
- Push files from a project to the Git repository and download the Git repository as a compressed file.
- Import the compressed file into a deployment space. The imported compressed file becomes a code package asset in the space. For more information, see:
- Deploy the Shiny app. Refer to Deploying Shiny apps from the deployment space.
If you want to deploy a Shiny app that was transferred to the deployment space as a code package, you must first define its software specification. Refer to Preparing code packages that contain Shiny apps before deployment.
The standard and recommended ways to move assets (for example, Shiny apps) to a deployment space are:
- Exporting a Watson Studio project and importing it into a deployment space.
- If applicable: making a snapshot of a Git repository and then downloading it.
Deploying Shiny apps from the deployment space
For more information, see Deploying Shiny Apps from the GUI.
If you want to share your deployed Shiny app with others, refer to Access modes for Shiny applications.
If your deployed application uses large files, such as custom R installation packages, you must use a Storage Volume. For more information, see Connecting your Shiny application to a persistent storage volume.
The initial load of a Shiny application might result in an empty page if the app is retrieving many dependent libraries from an external network. To resolve this, try refreshing the app after a while. This issue can be corrected by sourcing the dependent libraries locally and by bundling them into the Shiny app. For more information, see Creating R scripts and Shiny apps.
Access modes for Shiny applications
To ensure that the users can access the right amount of data, you can use the following security modes to limit or share access to your Shiny application deployment:
- Use the Collaborators option in your deployment space if you want to keep your Shiny application private. For more information, see Deployment space collaborator roles and permissions.
- Use the Authenticated users option if you want to share you Shiny application with Cloud Pak for Data users.
- Use the Anyone who has the URL option to share your Shiny application with anyone who has the link to access your application.
Note: Users that can access your Shiny application have no impact on what the application code is doing. Shiny applications do not display data specific to the user that accesses the application.
Preparing code packages that contain Shiny apps before deployment
Depending on the software specification that was used to create the Shiny app, before you deploy it, you must add a code-package.json file to the root of your package directory:
{
"entry_points": [{
"application_type":"RShiny",
"dependencies": {
"software_specification": "rstudio_r4.2"
}
}]
}
Software specifications available for Shiny apps: rstudio_r4.2 and rstudio-23.1-r4.2 (for x86) and shiny-r3.6 (deprecated, used for x86 and PPC).
If a folder or a subfolder contains RShiny App files (that is files with the names app.R, ui.R or server.R), all files in that folder are considered to belong to the Shiny app (including .R files). Otherwise, all .R files are considered R script assets.
Accessing data with Shiny application deployment dashboard
You can use Shiny application dashbaords for a shared data connection with other users. Any data connection with personal credentials that is shared within the deployment space can be accessed by users that have access to the Shiny application.
You can use access modes in Shiny applications to modify user access to your data. For more information, see Access modes for Shiny applications.
Parent topic: Managing predictive deployments