test/explore.R

explore <- function(dataset, ...) {
  require(shiny)
  require(ggplot2)

  app <- list(
    ui = ,
    server = function(input, output) {
     
      data <- reactive({
        if (is.null(input$sampleSize))
          dataset
        else
          dataset[sample(nrow(dataset), input$sampleSize),]
      })
     
      output$plot <- renderPlot({
        
        p <- ggplot(data(), 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)
      
    }
  )
  runApp(app, ...)
}
gusef/IrisViewer documentation built on May 30, 2019, 6:55 p.m.