ShinyApp Presentation

Jun Zhang
March 28 2020

Introduction

The Shiny App I created uses the iris dataset in R. It is a simple app that compares the relationships between sepal length and sepal width of different species.

Sources

The link of the Shiny App is here, and the codes can be found on my Github page.

Ui.R

library(shiny)

# Define UI for application that draws a histogram
shinyUI(fluidPage(

  # Application title
  titlePanel("Iris Data"),

  sidebarLayout(
    sidebarPanel(
        radioButtons(inputId = "dataSource", label = "Choose a Species?", 
                     choices = list("Setosa", "Versicolor", "Virginica"), 
                     selected = "Setosa")
    ),


    mainPanel(
        conditionalPanel(
            condition="input.dataSource == 'Setosa'",
            plotOutput("SetosaPlot")
        ), 
        conditionalPanel(
            condition="input.dataSource == 'Versicolor'",
            plotOutput("VersicolorPlot")
        ), 
        conditionalPanel(
            condition="input.dataSource == 'Virginica'",
            plotOutput("VirginicaPlot")
        )
    )
  )
))

<!–html_preserve–>

Iris Data

<!–/html_preserve–>

Server.R

library(shiny)
library(dplyr)

data(iris)

# Define server logic required to draw a histogram
shinyServer(function(input, output) {

  output$SetosaPlot <- renderPlot({
      setosa <- filter(iris, Species == "setosa")
      plot(setosa$Sepal.Length, setosa$Sepal.Width, col=2, pch=19, 
           xlab="Speal Length", ylab="Sepal Width")
  })

  output$VersicolorPlot <- renderPlot({
      versicolor <- filter(iris, Species == "versicolor")
      plot(versicolor$Sepal.Length, versicolor$Sepal.Width, col=3, pch=19, 
           xlab="Speal Length", ylab="Sepal Width")
  })

  output$VirginicaPlot <- renderPlot({
      virginica <- filter(iris, Species == "virginica")
      plot(virginica$Sepal.Length, virginica$Sepal.Width, col=4, pch=19, 
           xlab="Speal Length", ylab="Sepal Width")
  })

})