A Shiny App that is Easy on the Eyes

Regis O'Connor
December 30, 2016

Caption for the picture.

Never Give Up

Shinyio just didn't seem to like me. I wrote three clever apps yet none deployed correctly. I was on the verge of simply parsing an example from class even if it cost me points. Then I remembered why I started this Data Science journey 12 months ago. My goal was, and is, to master the tools that create awesome data visualizations. Shinyio is critical to that process because it is an easy way to share the analysis broadly. Here you see my fourth - and successfully deployed attempt that is an exercise in incorporating photography into a shiny app. Thanks for looking it over.

A Iris data set refresher

str(iris)
'data.frame':   150 obs. of  5 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...

ui.R

This simple app has just 2 inputs - the type of iris species you want to see and a submit button. The trick was getting the .png files into the same directory as ui.R and server.R so that Shinyio could see it.

library(shiny)
shinyUI(fluidPage(
  titlePanel("Spring Will Be Here Soon!"),
  sidebarLayout(
  sidebarPanel(
    selectInput("species", "Which species of Iris do you want to see?",
                c("setosa" = 1,
                  "versicolor" = 2,
                  "virginica" = 3)),
    submitButton("Show me the Flower!")

  ),
  mainPanel(
    imageOutput("image1"))
  )
)) 

server.R

library(shiny)
shinyServer(function(input, output){
  active <- reactive({
  pic <- input$species
  flower <- if(pic==1){
    "Setosa - Wikipedia"
  } else if(pic == 1) {
      "Versicolor - Wikipedia"
  } else if(pic==3){
      "Viriginca - Wikipedia"
  }
  })
  output$image1 <- renderImage({
    # When input$species is setosa, filename is 1.png
    filename <- normalizePath(file.path(                                        paste(input$species, '.png', sep='')))

    # Return a list containing the filename and alt text
    list(src = filename,
         alt = ("Iris Species"))

  }, deleteFile = FALSE)
  })