我正在尝试为闪亮的应用选择我的数据的子集,但是选项不可见

时间:2019-01-16 23:08:09

标签: r shiny

我有一个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")
    )
    )
 )

0 个答案:

没有答案