So i am trying to get an interactive R markdown plot that subsets my data based on a selectInput and then generates a ggplot() from there. The error i am getting is
Error: data
must be a data frame, or other object coercible by fortify()
, not an S3 object with class mts/ts
teleost<-read.csv("teleost.csv")
teleost<-as.data.frame(teleost)
shiny::selectInput(
"species",
"Choose Species",
choices = sort(unique(teleost$sp.code)),
selected = "ARG",
)
mydata<-reactive({
filter(teleost, teleost$sp.code == input$species)
})
renderPlot({
ggplot2::ggplot(mydata(),x=length_mm.gp, y=rf_no.length) +
geom_bar(stat='identity') +
scale_y_continuous(name="Number of Fish",expand=expansion(mult=c(0,0.05))) +
scale_x_continuous(name="Total Length (mm)") +
theme_bw() +
facet_grid(rows=vars(year), cols=vars(sex), scales="free_y")
})
I have tried using, but no luck there either.
filter(teleost, sp.code %in% input$species`
The selectInput works and renders fine but no plot. Any help is appreicated.
(Sorry i cant supply the original data but its for ongoing research)
If i need to create a df for the issue to be solved let me know and i will.
TIA