Skip to content

Instantly share code, notes, and snippets.

@patilv
Created January 27, 2015 19:49
Show Gist options
  • Save patilv/460f7ee20def9a506714 to your computer and use it in GitHub Desktop.
Save patilv/460f7ee20def9a506714 to your computer and use it in GitHub Desktop.
INRUG-ShinyFinal
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
dataset=reactive(iris[(iris$Sepal.Length>=input$Sepal.Length[1] & iris$Sepal.Length<=input$Sepal.Length[2]&
iris$Sepal.Width>=input$Sepal.Width[1] & iris$Sepal.Width<=input$Sepal.Width[2]&
iris$Petal.Length>=input$Petal.Length[1] & iris$Petal.Length<=input$Petal.Length[2]&
iris$Petal.Width>=input$Petal.Width[1] & iris$Petal.Width<=input$Petal.Width[2]),])
output$subsetdata <- renderDataTable(
dataset(),options=list(pageLength=10))
output$summary <- renderPrint(
summary(dataset())
)
output$scatterplot=renderPlot(ggplot(dataset(),aes_string(x=input$xvar, y=input$yvar,color="Species"))+ geom_point()+
ggtitle("Scatter Plot")
)
output$boxplot=renderPlot(ggplot(dataset(),aes_string(x="Species",y=input$dvar))+ geom_boxplot()+
ggtitle("Box Plot")
)
})
library(shiny)
shinyUI(fluidPage(
tags$h2("Building a Shiny App"),
fluidRow(
column(3,
h5("Subsetting the iris data"),
p("Slide to select range of values. Default position of sliders cover the entire range of these variables"),
sliderInput("Sepal.Length", label = "Sepal.Length", min = min(iris$Sepal.Length),
max = max(iris$Sepal.Length),value=c(min(iris$Sepal.Length),max(iris$Sepal.Length))),
sliderInput("Sepal.Width", label = "Sepal.Width", min = min(iris$Sepal.Width),
max = max(iris$Sepal.Width), value = c(min(iris$Sepal.Width),max(iris$Sepal.Width))),
sliderInput("Petal.Length", label = "Petal.Length", min = min(iris$Petal.Length),
max = max(iris$Petal.Length), value = c(min(iris$Petal.Length),max(iris$Petal.Length))),
sliderInput("Petal.Width", label = "Petal.Width", min = min(iris$Petal.Width),
max = max(iris$Petal.Width), value = c(min(iris$Petal.Width),max(iris$Petal.Width))),
h5("Inputs for scatter plot"),
selectInput("xvar", "x-variable:", choices=names(iris[,-5])),
selectInput("yvar", "y-variable:", choices=names(iris[,-5]),selected = names(iris[2])),
h5("Input for box plot"),
selectInput("dvar", "Distribution of which variable for box plot?", choices=names(iris[,-5]),selected = names(iris[3]))#,
# submitButton("Update View", icon("refresh"))
),
fluidRow(
column(5,
HTML("<h5>Summary of Subsetted Data</h5>"),
verbatimTextOutput("summary"),
HTML("<br><br><h5>Data</h5>"),
dataTableOutput(outputId="subsetdata")),
column(4, plotOutput("scatterplot"),
plotOutput("boxplot"))
)
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment