31 July 2018

In this project mtcars dataset was used. User can smooth or facet the collumns and rows. This peer assessed assignment has two parts. First, you will create a Shiny application and deploy it on Rstudio's servers. Second, you will use Slidify or Rstudio Presenter to prepare a reproducible pitch presentation about your application.

R Markdown UI

library(shiny) library(ggplot2)

dataset <- mtcars

shinyUI(pageWithSidebar(

headerPanel("Mtcars Plotter"),

sidebarPanel(

sliderInput('sampleSize', 'Sample Size', min=10, max=nrow(dataset),
            value=min(10, nrow(dataset)), step=5, 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') ) ))

Server

library(shiny) library(ggplot2)

shinyServer(function(input, output) {

dataset <- reactive( { mtcars[sample(nrow(mtcars), 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$smooth)
  p <- p + geom_smooth()

print(p)

}, height=600 )

})

Plot