DRAFT: This module has unpublished changes.
Click this link to travel to our application!
Below is the raw code to recreate our app:
##First download these three packages if you haven't already: ggplot2, shiny, and readxl
library(shiny)
library(ggplot2)
library(readxl)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Shiny App: The Islands"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("samplesize","Choose the sample size",min = 1,max = 79,value = 79),
radioButtons("evar", "Choose an Explanatory Variable for Simple Linear Regression",
choices=list("House Number"="simdata$houseNum" ,"Age"="simdata$age","Height" = "simdata$height",
"Weight"="simdata$weight", "BMI" = "simdata$bmi"),
selected = NULL),
radioButtons("rvar", "Choose a Response Variable for Simple Linear Regression",
choices=list("House Number"="simdata$houseNum" ,"Age"="simdata$age","Height" = "simdata$height",
"Weight"="simdata$weight", "BMI" = "simdata$bmi"),
selected = NULL),
textInput("title", "What is the title of your graph?", value = "")
),
# Show a plot of the generated distribution
mainPanel(
#DISPLAY COMMANDS GO HERE
plotOutput("boxPlot"),
plotOutput("plot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
simdata <- reactive ({
island <- read.csv("islandData.csv")
islandSubset <- island[sample(input$samplesize),]
})
output$boxPlot <- renderPlot({
simdata <- simdata()
title1 <- paste("Boxplot with sample size of:", input$samplesize)
p <- ggplot(simdata,aes(x = simdata$gender, y = simdata$bmi, fill="red"))
p + geom_boxplot() + labs(title=title1)
})
output$plot <- renderPlot({
simdata <- simdata()
samplesize <- paste("Using a sample size of ", input$samplesize)
g <- ggplot(simdata, aes(x=eval(parse(text=input$evar)), y=eval(parse(text=input$rvar))))
g+geom_point()+labs(title = input$title, x=input$evar, y=input$rvar, subtitle=samplesize)+geom_smooth(method = "lm", se = FALSE)
})
}
# Run the application
shinyApp(ui = ui, server = server)
DRAFT: This module has unpublished changes.
Login