library(ggplot2)
library(dplyr)
library(reshape2)
library(readr)
data1 <- read_csv("Kaggle.csv")
data2 <- read_csv("country_population.csv")
data2 <- melt(data2, id.vars = c("Country Name", "Country Code", "Indicator Name", "Indicator Code"), variable.name = "Year", value.name = "Population")
data3 <- read_csv("life_expectancy.csv")
data3 <- melt(data3, id.vars = c("Country Name", "Country Code", "Indicator Name", "Indicator Code"), variable.name = "Year", value.name = "Life Expectancy")
years <- unique(data3$Year)
countries <- unique(data3$`Country Name`)
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
radioButtons(inputId = "secondgraphvariable",
label = "Choose a Variable for the Second Graph",
choices = c("Life Expectancy", "Population"),
selected = "Population"
),
selectInput(
inputId = "years",
label = "Choose years to display",
choices = years,
multiple = TRUE,
selected = c(2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013)
),
selectInput(
inputId = "country",
label = "Choose a country",
choices = countries,
selected = c("Tanzania", "United States", "India", "China"),
multiple = TRUE),
selectInput(
inputId = "xaxis",
label = "Choose a Variable for the X-axis of the First Graph",
choices = colnames(data1),
selected = "Gini coefficient 2005-2013"
),
selectInput(
inputId = "yaxis",
label = "Choose a Variable for the Y-axis of the First Graph",
choices = colnames(data1),
selected = "Gross domestic product GDP percapta"
)
),
mainPanel(
plotOutput(outputId = "scatterplot"))
)
)
server <- function(input, output) {
output$scatterplot <- renderPlot({
req(input$xaxis)
req(input$yaxis)
scatter <- ggplot(data1, aes(x = input$xaxis, y = input$yaxis))+geom_point()
})
}
shinyApp(ui = ui, server = server)
The result is how the picture appears: