inst/examples/diamonds/server.R

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)

})

Try the rsconnect package in your browser

Any scripts or data that you put into this service are public.

rsconnect documentation built on Oct. 4, 2023, 5:07 p.m.