Skip to content

Instantly share code, notes, and snippets.

@angrycoffeemonster
Forked from jcheng5/server.R
Created January 2, 2013 18:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angrycoffeemonster/4436688 to your computer and use it in GitHub Desktop.
Save angrycoffeemonster/4436688 to your computer and use it in GitHub Desktop.
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
dataset <- reactive(function() {
diamonds[sample(nrow(diamonds), input$sampleSize),]
})
output$plot <- reactivePlot(function() {
p <- ggplot(dataset(), aes_string(x=input$x, y=input$y)) + geom_point()
if (input$color != 'None')
p <- p + aes_string(color=input$color)
facets <- paste(input$facet_row, '~', input$facet_col)
if (facets != '. ~ .')
p <- p + facet_grid(facets)
if (input$jitter)
p <- p + geom_jitter()
if (input$smooth)
p <- p + geom_smooth()
print(p)
}, height=700)
})
library(shiny)
library(ggplot2)
dataset <- diamonds
shinyUI(pageWithSidebar(
headerPanel("Diamonds Explorer"),
sidebarPanel(
sliderInput('sampleSize', 'Sample Size', min=1, max=nrow(dataset),
value=min(1000, nrow(dataset)), step=500, round=0),
selectInput('x', 'X', names(dataset)),
selectInput('y', 'Y', names(dataset), names(dataset)[[2]]),
selectInput('color', 'Color', c('None', names(dataset))),
checkboxInput('jitter', 'Jitter'),
checkboxInput('smooth', 'Smooth'),
selectInput('facet_row', 'Facet Row', c(None='.', names(dataset))),
selectInput('facet_col', 'Facet Column', c(None='.', names(dataset)))
),
mainPanel(
plotOutput('plot')
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment