Shiny data
library(Cairo)
library(dslabs)
library(shiny)
library(dslabs)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(googlesheets)
dataall<-read.csv("C:/Users/power/BST260/Project/BST260_ClassProject/5years.csv",header=T)
Happiness Score
# Define ui
ui <- fluidPage( # Dropdown menu that allows the user to choose a region
selectInput(inputId = "Country", label = "Select a country",
choices = as.list(levels(dataall$Country))),
plotOutput("scatterPlot")
)
# Define server
server <- function(input, output){
output$scatterPlot <- renderPlot({
USA<-subset(dataall,Country=="United States")
dataall %>% filter(Country == input$Country) %>%
ggplot(aes(x = Year, y = HScore)) +
geom_line() +
geom_line(mapping=aes(USA$Year,USA$HScore),color="red")+
xlab("Year") +
ylab("Happiness Score")+
ggtitle(sprintf("Comparison of Happiness Scores with United States")) +
#theme_bw()+
scale_x_continuous(limit=c(2014, 2018))
})
}
shinyApp(ui = ui, server = server)
##
## Listening on http://127.0.0.1:3124
GDP per Capita
# Define ui
ui <- fluidPage( # Dropdown menu that allows the user to choose a region
selectInput(inputId = "Country", label = "Select a country",
choices = as.list(levels(dataall$Country))),
plotOutput("scatterPlot")
)
# Define server
server <- function(input, output){
output$scatterPlot <- renderPlot({
USA<-subset(dataall,Country=="United States")
dataall %>% filter(Country == input$Country) %>%
ggplot(aes(x = Year, y = Economy)) +
geom_line() +
geom_line(mapping=aes(USA$Year,USA$Economy),color="red")+
xlab("Year") +
ylab("GDP per capita")+
scale_x_continuous(limit=c(2014, 2018))
})
}
shinyApp(ui = ui, server = server)
##
## Listening on http://127.0.0.1:4893
SOcial support
# Define ui
ui <- fluidPage( # Dropdown menu that allows the user to choose a region
selectInput(inputId = "Country", label = "Select a country",
choices = as.list(levels(dataall$Country))),
plotOutput("scatterPlot")
)
# Define server
server <- function(input, output){
output$scatterPlot <- renderPlot({
USA<-subset(dataall,Country=="United States")
dataall %>% filter(Country == input$Country) %>%
ggplot(aes(x = Year, y = Family)) +
geom_line() +
geom_line(mapping=aes(USA$Year,USA$Family),color="red")+
xlab("Year") +
ylab("Social support")+
scale_x_continuous(limit=c(2014, 2018))
})
}
shinyApp(ui = ui, server = server)
##
## Listening on http://127.0.0.1:6865
Life expectance
# Define ui
ui <- fluidPage( # Dropdown menu that allows the user to choose a region
selectInput(inputId = "Country", label = "Select a country",
choices = as.list(levels(dataall$Country))),
plotOutput("scatterPlot")
)
# Define server
server <- function(input, output){
output$scatterPlot <- renderPlot({
USA<-subset(dataall,Country=="United States")
dataall %>% filter(Country == input$Country) %>%
ggplot(aes(x = Year, y = Life.expectancy)) +
geom_line() +
geom_line(mapping=aes(USA$Year,USA$Life.expectancy),color="red")+
xlab("Year") +
ylab("Life Expectancy")+
scale_x_continuous(limit=c(2014, 2018))
})
}
shinyApp(ui = ui, server = server)
##
## Listening on http://127.0.0.1:8326
Freedom
# Define ui
ui <- fluidPage( # Dropdown menu that allows the user to choose a region
selectInput(inputId = "Country", label = "Select a country",
choices = as.list(levels(dataall$Country))),
plotOutput("scatterPlot")
)
# Define server
server <- function(input, output){
output$scatterPlot <- renderPlot({
USA<-subset(dataall,Country=="United States")
dataall %>% filter(Country == input$Country) %>%
ggplot(aes(x = Year, y = Freedom)) +
geom_line() +
geom_line(mapping=aes(USA$Year,USA$Freedom),color="red")+
xlab("Year") +
ylab("Freedom")+
scale_x_continuous(limit=c(2014, 2018))
})
}
shinyApp(ui = ui, server = server)
##
## Listening on http://127.0.0.1:7833
Generosity
# Define ui
ui <- fluidPage( # Dropdown menu that allows the user to choose a region
selectInput(inputId = "Country", label = "Select a country",
choices = as.list(levels(dataall$Country))),
plotOutput("scatterPlot")
)
# Define server
server <- function(input, output){
output$scatterPlot <- renderPlot({
USA<-subset(dataall,Country=="United States")
dataall %>% filter(Country == input$Country) %>%
ggplot(aes(x = Year, y = Generosity)) +
geom_line() +
geom_line(mapping=aes(USA$Year,USA$Generosity),color="red")+
xlab("Year") +
ylab("Generosity")+
scale_x_continuous(limit=c(2014, 2018))
})
}
shinyApp(ui = ui, server = server)
##
## Listening on http://127.0.0.1:3458
Trust
# Define ui
ui <- fluidPage( # Dropdown menu that allows the user to choose a region
selectInput(inputId = "Country", label = "Select a country",
choices = as.list(levels(dataall$Country))),
plotOutput("scatterPlot")
)
# Define server
server <- function(input, output){
output$scatterPlot <- renderPlot({
USA<-subset(dataall,Country=="United States")
dataall %>% filter(Country == input$Country) %>%
ggplot(aes(x = Year, y = Trust)) +
geom_line() +
geom_line(mapping=aes(USA$Year,USA$Trust),color="red")+
xlab("Year") +
ylab("Trust")+
scale_x_continuous(limit=c(2014, 2018))
})
}
shinyApp(ui = ui, server = server)
##
## Listening on http://127.0.0.1:5969