November 21, 2019

Introduction

The Iris dataset

summary(iris)
##   Sepal.Length    Sepal.Width     Petal.Length    Petal.Width   
##  Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100  
##  1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300  
##  Median :5.800   Median :3.000   Median :4.350   Median :1.300  
##  Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199  
##  3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800  
##  Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500  
##        Species  
##  setosa    :50  
##  versicolor:50  
##  virginica :50  
##                 
##                 
## 

About the IrisApps

  • Form of input used: radio button and slider input.
  • The ui consists of two layouts:
    • the sidebar panel, consists of radio buttons representing Iris's attributes, where the user can select to view in the form of histogram. The sidebar panel also consists of a slider input to specify bins range.
    • the main panel shows the generated histogram.

ui.r code

library(shiny)

ui <- fluidPage(

titlePanel("IrisApps"),

sidebarLayout(
    sidebarPanel(
        helpText("This Apps provide visualization of Iris dataset 
        in the form of Histogram, depending on the Iris's attribute 
        that the user select."),
        radioButtons("option", "Choose Iris attribute:",
        list("Sepal.Length"='a', "Sepal.Width"='b', "Petal.Length"='c',
        "Petal.Width"='d')),
        sliderInput("bins", "Specify the bins range:", min = 1, max = 50, 
        value = 30)
    ),
mainPanel(mainPanel(plotOutput("distPlot")) )))

server.r code

server <- function(input, output) {

output$distPlot <- renderPlot({
    if(input$option=='a'){       
        i<-1     }     
    if(input$option=='b'){       
        i<-2     }     
    if(input$option=='c'){       
        i<-3     }     
    if(input$option=='d'){       
        i<-4     }
    
    x    <- iris[, i] 
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    hist(x, main = "Histogram of Iris Dataset", xlab = "Iris Attribute", 
    ylab = "Frequency", breaks = bins, col = 'blue', border = 'white')
}) }