Я пытаюсь выбрать подмножество своих данных для блестящего приложения, но параметры не отображаются - PullRequest
0 голосов
/ 17 января 2019

У меня есть приложение Shiny, которое позволяет пользователю выбирать переменную x и y из данных, и она разделяется другой переменной на разные цвета. Это хорошо выглядит, но, поскольку есть много данных, это выглядит очень грязно.

Я хочу построить подмножество моих данных по годам, которое доступно в моем наборе данных. Я использовал selectInput для этого, но при запуске я получаю пустое раскрывающееся окно, и данные не отображаются (предположительно, потому что ничего не выбрано).

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
} )    

})

и

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")
    )
    )
 )
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...