Created
November 29, 2017 18:03
-
-
Save patilv/0e8fee078f0fab4e2ead185d39dc362c to your computer and use it in GitHub Desktop.
shiny_App_Tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
) | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
shinyUI(fluidPage( | |
fluidRow( | |
tags$h2("Building a Shiny App"), | |
column(4, | |
h3("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)))), | |
column(3, | |
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)))), | |
column(5, | |
fluidRow( | |
column(6, | |
h3("Inputs for scatter plot"), | |
selectInput("xvar", "x-variable:", choices=names(iris[,-5])), | |
selectInput("yvar", "y-variable:", choices=names(iris[,-5]),selected = names(iris[2])) | |
), | |
column(6, | |
h3("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(3, | |
HTML("<h5>Summary of Subsetted Data</h5>"), | |
verbatimTextOutput("summary") | |
), | |
column(4, | |
HTML("<br><br><h5>Data</h5>"), | |
dataTableOutput(outputId="subsetdata")), | |
column(5, | |
fluidRow( | |
column(6,plotOutput("scatterplot") ), | |
column(6,plotOutput("boxplot")) ) | |
) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment