Skip to content

Commit

Permalink
adding sample apps
Browse files Browse the repository at this point in the history
  • Loading branch information
charleyferrari committed Sep 26, 2018
1 parent 78ccf00 commit bca3424
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
46 changes: 46 additions & 0 deletions module3/Sample Apps/ggplot-reactive.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
library(ggplot2)
library(dplyr)
library(shiny)

df <- read.csv('https://raw.githubusercontent.com/charleyferrari/CUNY_DATA608/master/lecture3/Sample%20Code/hpi.csv')
df$DATE <- as.POSIXct(strptime(df$DATE, format = '%m/%d/%y'))

ui <- fluidPage(
headerPanel('Housing Price Explorer'),
sidebarPanel(
selectInput('seas', 'Seasonality', unique(df$Seasonality), selected='SA'),
selectInput('metro', 'Metro Area', unique(df$Metro), selected='Atlanta'),
selectInput('tier', 'Housing Tier', unique(df$Tier), selected='High')
),
mainPanel(
plotOutput('plot1'),
verbatimTextOutput('stats')
)
)

server <- shinyServer(function(input, output, session) {

selectedData <- reactive({
dfSlice <- df %>%
filter(Seasonality == input$seas, Metro == input$metro)
})

output$plot1 <- renderPlot({

dfSlice <- df %>%
filter(Seasonality == input$seas, Metro == input$metro)

ggplot(selectedData(), aes(x = DATE, y = HPI, color = Tier)) +
geom_line()
})

output$stats <- renderPrint({
dfSliceTier <- selectedData() %>%
filter(Tier == input$tier)

summary(dfSliceTier$HPI)
})

})

shinyApp(ui = ui, server = server)
42 changes: 42 additions & 0 deletions module3/Sample Apps/ggplot-simple.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
library(ggplot2)
library(dplyr)
library(plotly)
library(shiny)

df <- read.csv('https://raw.githubusercontent.com/charleyferrari/CUNY_DATA608/master/lecture3/Sample%20Code/hpi.csv')
df$DATE <- as.POSIXct(strptime(df$DATE, format = '%m/%d/%y'))

ui <- fluidPage(
headerPanel('Housing Price Explorer'),
sidebarPanel(
selectInput('seas', 'Seasonality', unique(df$Seasonality), selected='SA'),
selectInput('metro', 'Metro Area', unique(df$Metro), selected='Atlanta'),
selectInput('tier', 'Housing Tier', unique(df$Tier), selected='High')
),
mainPanel(
plotOutput('plot1'),
verbatimTextOutput('stats')
)
)

server <- function(input, output, session) {

output$plot1 <- renderPlot({

dfSlice <- df %>%
filter(Seasonality == input$seas, Metro == input$metro)

ggplot(dfSlice, aes(x = DATE, y = HPI, color = Tier)) +
geom_line()
})

output$stats <- renderPrint({
dfSlice <- df %>%
filter(Seasonality == input$seas, Metro == input$metro, Tier == input$tier)

summary(dfSlice$HPI)
})

}

shinyApp(ui = ui, server = server)
47 changes: 47 additions & 0 deletions module3/Sample Apps/plotly-simple.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
library(ggplot2)
library(dplyr)
library(plotly)
library(shiny)

df <- read.csv('https://raw.githubusercontent.com/charleyferrari/CUNY_DATA608/master/lecture3/Sample%20Code/hpi.csv')
df$DATE <- as.POSIXct(strptime(df$DATE, format = '%m/%d/%y'))

ui <- fluidPage(
headerPanel('Housing Price Explorer'),
sidebarPanel(
selectInput('seas', 'Seasonality', unique(df$Seasonality), selected='SA'),
selectInput('metro', 'Metro Area', unique(df$Metro), selected='Atlanta'),
selectInput('tier', 'Housing Tier', unique(df$Tier), selected='High')
),
mainPanel(
plotlyOutput('plot1'),
verbatimTextOutput('stats')
)
)

server <- function(input, output, session) {

selectedData <- reactive({
dfSlice <- df %>%
filter(Seasonality == input$seas, Metro == input$metro)
})

output$plot1 <- renderPlotly({

dfSlice <- df %>%
filter(Seasonality == input$seas, Metro == input$metro)

plot_ly(selectedData(), x = ~DATE, y = ~HPI, color = ~Tier, type='scatter',
mode = 'lines')
})

output$stats <- renderPrint({
dfSliceTier <- selectedData() %>%
filter(Tier == input$tier)

summary(dfSliceTier$HPI)
})

}

shinyApp(ui = ui, server = server)

0 comments on commit bca3424

Please sign in to comment.