Skip to content

Instantly share code, notes, and snippets.

@sureshgorakala
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sureshgorakala/8942533 to your computer and use it in GitHub Desktop.
Save sureshgorakala/8942533 to your computer and use it in GitHub Desktop.
Shiny Server Demo
library(shiny)
shinyServer(function(input, output) {
#ds = read.csv("data.csv")
ds = local(get(load("C:/Users/S769346/Desktop/SAFETY DATA ANALYSIS/SAFETY DATA ANALYSIS/test/df.rData")))
xn = as.POSIXct(ds$"Date.of.Occurence",format="%m/%d/%Y")
ds["year"] = as.numeric(format(xn,"%Y"))
ds["month"] = as.numeric(format(xn,"%m"))
dataset <- reactive(function() {
ds[which(ds$"year" == input$Year),]
})
output$plot <- reactivePlot(function() {
db = dataset()
hist(as.numeric(db$"month"),breaks = "Sturges",col=c('blue','red','green'),labels=T)
if(input$select == "Flight.Phase")
{
da = db[which(db[input$select] == "Take-off"),]
hist(as.numeric(da$"month"),breaks = "Sturges",col=c('blue','red','green'),labels=T)
}
})
output$summary <- renderPrint({
db = dataset()
summary(db[input$select])
})
})
library(shiny)
#ds = read.csv("data.csv")
ds = local(get(load("C:/Users/S769346/Desktop/SAFETY DATA ANALYSIS/SAFETY DATA ANALYSIS/test/df.rData")))
x = names(ds)
shinyUI(pageWithSidebar(
headerPanel("Shiny Server Demo"),
sidebarPanel(
sliderInput('Year', 'Year', min=2010, max=2012,
value=min(2010,2012), step=1, round=0),
selectInput('select', 'Select Criteria', c(x[3],x[9],x[10],x[11],x[12],x[26]))
),
mainPanel(
plotOutput('plot'),
verbatimTextOutput("summary")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment