Deploying Shiny Apps with cpdctl
Deploy your Shiny app with cpdctl.
If you don't have a Shiny app, create it. You can type this example code in the R Studio console:
library(shiny)
ui <- fluidPage(
"Hello, world!"
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
Alternatively, create a sample app directly from the GUI. Refer to Creating an automatically generated app from RStudio GUI.
Exporting project assets and importing it into a deployment space is the standard way to move assets (for example, Shiny apps) to a deployment space. For more information, see Importing spaces and projects.
If you use cpdctl, you can deploy Shiny apps from two different asset types:
Deploying a Shiny app with cpdctl
To deploy a shiny app with cpdctl:
-
Set your shiny app metadata. Refer to these examples:
#Shiny App Name: shiny_deployment_name="sampleapp-cpdctl-3"
#asset metadata specification asset = { "id" : "c0d7c50e-455a-48bb-b3d2-a987ff0791fe" } asset_json = json.dumps(asset) asset_json
#hardware metadata specification hardware_spec_details = { "id" : "f3ebac7d-0a75-410c-8b48-a931428cc4c5", "rev" : 'latest', "name" : "XS", "num_nodes" : 1 } hardware_spec_details_json = json.dumps(hardware_spec_details) hardware_spec_details_json
#shiny metadata specification rshiny_details = { "authentication" : "members_of_deployment_space", "parameters" : { "serving_name" : "shiny15" } } rshiny_details_json = json.dumps(rshiny_details) rshiny_details_json
-
Deploy your Shiny app:
! cpdctl ml deployment create --space-id {space_id} --name {shiny_deployment_name} --asset '{asset_json}' --r-shiny '{rshiny_details_json}' --hardware-spec '{hardware_spec_details_json}'
For batch deployments, The hardware_spec.num_nodes
parameter is not supported.
Deploying a code package that contains a Shiny app with cpdctl
For more information, see Creating and registering code package assets by using CPDCTL.
To deploy a code package that contains a Shiny app with cpdctl:
-
Set your shiny app metadata. Refer to these examples:
#Shiny App Name: shiny_deployment_name="sampleapp-cpdctl-3"
#asset metadata specification asset = { "id" : "c0d7c50e-455a-48bb-b3d2-a987ff0791fe" } asset_json = json.dumps(asset) asset_json
#hardware metadata specification hardware_spec_details = { "id" : "f3ebac7d-0a75-410c-8b48-a931428cc4c5", "rev" : 'latest', "name" : "XS", "num_nodes" : 1 } hardware_spec_details_json = json.dumps(hardware_spec_details) hardware_spec_details_json
#shiny metadata specification rshiny_details = { "authentication" : "members_of_deployment_space", "parameters" : { "serving_name" : "shiny3" "code_package" : { "path" : "RShiny/apps/app1" } } }
-
Deploy your Shiny app:
! cpdctl ml deployment create --space-id {space_id} --name {shiny_deployment_name} --asset '{asset_json}' --r-shiny '{rshiny_details_json}' --hardware-spec '{hardware_spec_details_json}'
For batch deployments, The hardware_spec.num_nodes
parameter is not supported.
Parent topic: Deploying Shiny apps in Watson Machine Learning