Skip to content

Instantly share code, notes, and snippets.

@tcash21
Created September 11, 2013 19:33
Show Gist options
  • Save tcash21/6528653 to your computer and use it in GitHub Desktop.
Save tcash21/6528653 to your computer and use it in GitHub Desktop.
library(shiny)
library(ggplot2)
library(shinyIncubator)
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output, session) {
getData <- function(){
x <- seq(Sys.Date() - (input$nobs - 1), Sys.Date(), by="days")
y <- rnorm(input$nobs, 5, 100)
Sys.sleep(1)
return(data.frame(the_date=x, value=y))
}
output$chart <- renderPlot({
result <- getData()
g <- ggplot(result, aes(x=the_date, y=value)) + geom_point()
print(g)
})
output$table <- renderChart2({
result <- getData()
dTable(result, aaSorting = list(c(1, "asc")))
})
})
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel(title=""),
# Sidebar with controls to select a dataset and specify the number
# of observations to view
sidebarPanel(
numericInput("nobs", "Number Observations", value=1000),
submitButton("Submit")
),
# Show a summary of the dataset and an HTML table with the requested
# number of observations
mainPanel(
plotOutput("chart"),
chartOutput("table", "datatables")
,width="1000")
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment