【发布时间】:2019-08-03 04:51:00
【问题描述】:
希望只是一个简单的问题,我已在代码中添加了 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)
【问题讨论】: