Using R Shiny

SherlockML supports building R Shiny applications. R Shiny offers a flexible interface for building interactive dashboards entirely in R (you don’t need to write any JavaScript). The Shiny gallery has some great examples of dashboards, and the shiny-examples repository on github for many more that can be used as starting point for your own app.

Developing the application

When you are just starting out, you probably want to develop the application without exposing it to other people in your project.

The easiest way of doing this is to just create an RStudio server, open a terminal in that server and run the following commands:

$ sudo sv stop rstudio
$ shiny-server

This has stopped the RStudio server running on that instance, freeing the port for our application, and started a shiny server that will serve all the applications in your project workspace.

Now we need to write the code for our application. We will use one of the applications in the R Shiny gallery as an example: k-means clustering of the Iris dataset.

Let’s start by creating a directory in the project workspace:

$ mkdir -p /project/iris-kmeans

Create a file called app.R in /project/iris-kmeans, with the following contents:

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)

This code defines an application that will compute k-means clusters of the Iris data, allowing the user which features to use for the clustering and how many clusters to use.

Now you can click on the name of your server and a tab will open with a file tree of the project workspace. Access your app by clicking on the iris-kmeans directory, and you will see your application:


Carry on developing your app. When you make changes to your code, stop the app server by typing Ctrl-C in the same terminal as the one in which you started the app, and restart it by running the same command.

Deploying the application

You have now developed a great dashboard, and you want to let other members of your project access it. SherlockML supports hosting R Shiny applications. Head to the Apps tab in SherlockML, click New, followed by R Shiny. You will be prompted to enter a name for your app.


Choose a name and click Create App. You will then be taken to the App settings page.

You will need to make the following changes to the application settings:

  • Change the APP DIRECTORY to /project/iris-kmeans.

Save your application by clicking the Save button, then click Start app to actually start your server. After a few seconds, you will see the status of your app change to Running. At this point, a URL will appear. Select that URL and place it in your browser search bar. You will be taken to the application! Behind the scenes, SherlockML verifies that you are an observer in the project that the app belongs to.

Sharing your application

To share the application with a team member who is an observer in the project, just give them the URL of the application!

To invite people to your project, go to the Collaborators page, enter their SherlockML username or the email that they used to sign up to SherlockML, and assign them observer status.