Skip to content
Permalink
Browse files

ENH: Add demo shiny app

  • Loading branch information
pan14001 committed Mar 29, 2018
1 parent dff14ef commit 584312d0f23a6d7dc4a868187a1b19c02f75d375
Showing with 60 additions and 0 deletions.
  1. +31 −0 server.R
  2. +29 −0 ui.R
@@ -0,0 +1,31 @@
library(shiny)
library(ggplot2)

function(input, output) {
dataset <- reactive({
diamonds[sample(nrow(diamonds), input$sampleSize),]
})

output$plot <- renderPlot({

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)
}
29 ui.R
@@ -0,0 +1,29 @@
library(shiny)
library(ggplot2)

dataset <- diamonds

fluidPage(

titlePanel("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')
)
)

0 comments on commit 584312d

Please sign in to comment.
You can’t perform that action at this time.