选择变量时selectInput不起作用

时间:2019-03-12 16:16:58

标签: r ggplot2 shiny

希望只是一个简单的问题,我已经在代码中添加了selectInput函数并将其链接到服务器,但是,每当我在应用程序中更改“年份”时,散点图都不会更改基于在这一年。

我缺少一些代码吗?

library(shiny)
library(ggplot2)
pigs <- read.csv("pigs_data.csv")
# Define UI for application 
ui <- fluidPage(
# Application title
titlePanel("Pig Breeding"),
sidebarLayout( 
sidebarPanel(
  #Allows user to choose a year which changes the distribution of plot points
selectInput(inputId = "year",
            label = "Choose a year:",
            choices = c(2016, 2017, 2018),
            selectize = FALSE
            )
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("scatterplot")
)
)
)
# Define server logic 
server <- function(input, output) {
output$scatterplot <- renderPlot({
                    input$year
                    ggplot(pigs, 
                    aes(x = sow_count, y = species, col = species)) + 
                    geom_point() +
                    facet_grid(. ~year)
})
}
# Run the application 
shinyApp(ui = ui, server = server)

0 个答案:

没有答案