0

I have a Shiny app which allows the user to select the x variable and y variable from the data, and it is split by another variable into different colours. This plots fine, but as there's lots of data it looks very messy.

I want to plot a subset of my data by year, which is available in my dataset. I have used selectInput for this, but when I run that I get an empty dropdown box, and no data is plotted (presumably because nothing is selected).

server.R
collated <- read.csv("collated.csv")

contVariables <- c("percent_ctax_a_c" = "Percentage of population in council tax bands A - C",
               "percent_ctax_d_e" = "Percentage of population in council tax bands D - E",
               "percent_ctax_f_h" = "Percentage of population in council tax bands F - H",
               "crimes_per_10000_popn" = "Crimes (per 10'000 population)",
               "hosp_admissions_per_100000_popn" = "Hospital Admissions (per 100'000 population)",
               "median_house_price_GBP" = "Median House Price (GBP)",
               "mean_year_jobseekers_ages_25_49" = "Percentage of population aged 25-49 claiming Jobseekers Allowance",
               "percent_waste_recycled" = "Percentage of waste recycled",
               "waste_kg_per_capita" = "Waste per capita (kg)",
               "percent_people_near_derelict" = "Percentage of people near derelict sites")

shinyServer(function(input, output) {

output$plot <- renderPlot( {
    collated <- subset(collated, year %in% input$year)
    p <- ggplot(data = collated) +
        aes_string(x=input$x, y=input$y)
    p <- p + geom_point(aes(col = collated$Council)) +
      labs(col="Local Authority") +
            xlab(contVariables[input$x]) + 
            ylab(contVariables[input$y])
    p
} )    

})

and

ui.R
collated <- read.csv("collated.csv")

variables <- list(
continuous=c("Percentage of population in council tax bands A - C" = "percent_ctax_a_c",
             "Percentage of population in council tax bands D - E" = "percent_ctax_d_e",
             "Percentage of population in council tax bands F - H" = "percent_ctax_f_h",
             "Crimes (per 10'000 population)" = "crimes_per_10000_popn",
             "Hospital Admissions (per 100'000 population)" = "hosp_admissions_per_100000_popn",
             "Median House Price (GBP)" = "median_house_price_GBP",
             "Percentage of population aged 25-49 claiming Jobseekers Allowance" = "mean_year_jobseekers_ages_25_49",
             "Percentage of waste recycled" = "percent_waste_recycled",
             "Waste per capita (kg)" = "waste_kg_per_capita",
             "Percentage of people near derelict sites" = "percent_people_near_derelict"),

categorical=c("Data zone" = "DataZone", 
             "Intermediate zone" = "InterZone", 
             "Local Authority" = "Council", 
             "Label" = "Label", 
             "Year" = "year")
)

fluidPage(
titlePanel("Data"),
sidebarLayout(
    sidebarPanel(
        selectInput("x", "Variable plotted on x-Axis", variables$continuous, selected ="percent_people_near_derelict"),
        selectInput("y", "Variable plotted on y-Axis", variables$continuous, selected ="median_house_price_GBP"),
        selectInput("year", "Year", choices = levels(collated$year), multiple = FALSE)),
    mainPanel(
        plotOutput("plot")
    )
    )
 )
PharmDataSci
  • 115
  • 7
  • 2
    A [minimal example](https://stackoverflow.com/questions/48343080/how-to-convert-a-shiny-app-consisting-of-multiple-files-into-an-easily-shareable) would be helpful to be able to diagnose the issue. Are you sure your `collated` data frame gets read in correctly? – phalteman Jan 17 '19 at 00:21
  • Thanks for the feedback, I fixed it with this: selectInput("year", "Year", choices = c(1993:2018), multiple = FALSE)), I'm not 100% what the problem with using the column for the data was, I've used a column for an additional input, and that works fine. – PharmDataSci Jan 17 '19 at 00:58

0 Answers0