Skip to content

Instantly share code, notes, and snippets.

@angrycoffeemonster
Last active December 10, 2015 12:58
Show Gist options
  • Save angrycoffeemonster/4437646 to your computer and use it in GitHub Desktop.
Save angrycoffeemonster/4437646 to your computer and use it in GitHub Desktop.
Example test for HACS analysis
library(shiny)
library(datasets)
setwd("~/Downloads/R/E6")
E6Data <- read.table("dataHacs2.csv", header=TRUE, sep="," )
# We tweak the "am" field to have nicer factor labels. Since this doesn't
# rely on any user inputs we can do this once at startup and then use the
# value throughout the lifetime of the application
# mpgData <- E6Data
# mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual"))
# Define server logic required to plot various variables against mpg
shinyServer(function(input, output) {
# Compute the forumla text in a reactive function since it is
# shared by the output$caption and output$mpgPlot functions
formulaText <- reactive(function() {
paste("E6Data ~", input$variable)
})
# Return the formula text for printing as a caption
output$caption <- reactiveText(function() {
formulaText()
})
# Generate a plot of the requested variable against mpg and only
# include outliers if requested
output$E6DataPlot <- reactivePlot(function() {
boxplot(as.formula(formulaText()),
data = E6Data,
outline = input$outliers)
})
})
library(shiny)
# Define UI for miles per gallon application
shinyUI(pageWithSidebar(
# Application title
headerPanel("Errors per Group clear(c) medium(m) obscured(o)"),
# Sidebar with controls to select the variable to plot against mpg
# and to specify whether outliers should be included
sidebarPanel(
selectInput("variable", "Variable:",list("Clear" = "c","Medium" = "m","Obscured" = "o")),
checkboxInput("outliers", "Show outliers", FALSE)
),
mainPanel()
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment