Jun Zhang
March 28 2020
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.
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–>
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")
})
})