I'm quite new to R and am currently trying to create a simple web app with shiny that plots the longley dataset from R. I want the user to be able to select which trend they want to plot, hence the selctinput in the ui, but I'm currently running into the problem "x and y lengths differ" screenshot of the problem: https://i.stack.imgur.com/zGOtb.png
Below is my reprex
library(shiny)
#> Warning: package 'shiny' was built under R version 4.1.3
mydata <- as.data.frame(longley)
ui<- fluidPage(titlePanel("Economic Data"),
sidebarLayout(
sidebarPanel(
selectInput("Trends", label = ("Trend Index"),
list("GNP.deflator","GNP","Unemployed","Armed.Forces","Population","Year","Employed"),
selected = "GNP", multiple = TRUE),
),
mainPanel(
plotOutput(outputId = "lineplot", height = "300px")
)
))
server <- function(input, output) {
output$lineplot <- renderPlot({
color = "434343"
par(mar= c(4, 4, 1, 1))
plot(x = mydata$year, y = "Trends", type = "l", xlab = "Date", ylab = "Trend Index",
col = color, fg = color, col.lab = color, col.axis = color)
})
}
shinyApp(ui = ui, server = server)`
Thanks in advance for any help [1]: https://i.stack.imgur.com/zGOtb.png