0
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:

enter image description here

camille
  • 16,432
  • 18
  • 38
  • 60
Tuti
  • 31
  • 3
  • 1
    do you need to return `scatter` or omit assigning the plot ie remove `scatter <- ` – user20650 Aug 01 '18 at 14:04
  • 3
    Please consider making your example reproducible, that makes it easier to help. For tips on how to do that, see; [How to make a Shiny app reproducible example?](https://stackoverflow.com/questions/48343080). – Florian Aug 01 '18 at 14:04
  • 1
    @user20650 . Thank you very much. The trick was to omit the scatter <- I will also try to make my code more reproducible next time. – Tuti Aug 01 '18 at 14:21

0 Answers0