# Launch an Interactive R Shiny App

cnvrg is designed to help with all parts of your ML life cycle and that includes supporting comprehensive R functionality. One of the use cases supported by R is the ability to launch dynamic and interactive visualization dashboards using R Shiny. cnvrg has full support for R Shiny and in this tutorial, we will launch a simple example dashboard.

# Create a New Project

  1. Go to Projects and click Start Project.
  2. Name the project r-shiny.

# Add the R Shiny code

Before we can launch and R Shiny app, we need to add the example code. You can of course use the workspaces feature to spin up an R Studio workspace where you could build your R Shiny code. However, we will simply be using pre-prepared code.

  1. Go to Files inside your r-shiny project.
  2. Click New File.
  3. Copy and paste the following code into the code editor:
    ui <- pageWithSidebar(
        headerPanel('Iris k-means clustering'),
        selectInput('xcol', 'X Variable', names(iris)),
        selectInput('ycol', 'Y Variable', names(iris),
        numericInput('clusters', 'Cluster count', 3,
                 min = 1, max = 9)
    server <- function(input, output, session) {
        # Combine the selected variables into a new data frame
        selectedData <- reactive({
            iris[, c(input$xcol, input$ycol)]
        clusters <- reactive({
            kmeans(selectedData(), input$clusters)
        output$plot1 <- renderPlot({
            palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
                "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))
            par(mar = c(5.1, 4.1, 0, 1))
                col = clusters()$cluster,
                pch = 20, cex = 3)
            points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
    shinyApp(ui = ui, server = server)
  4. Name the file: app.R
  5. Click Submit to save the file.

The above code will create a very simple R Shiny dashboard.

# Launch the R Shiny app

Now we can launch the code we just added:

  1. Go to Apps.
  2. Click Publish New App.
  3. Make sure R Shiny is selected.
  4. Set File as app.R.
  5. Click Advanced to expand the sub-heading and enter the following information:
    • Image: A compatible R image. For example the latest cnvrg_r image.
    • Compute: any compute of your choice.
  6. Click Publish.

cnvrg will now start doing all of the MLOps work to create a fully dynamic and shareable R Shiny dashboard. In just a few minutes all the configuration will be completed and you will be able to play around with the simple visualization of clustering.

Last Updated: 7/15/2020, 9:34:12 AM