Hello everyone,
I am working on a shiny app that contains:
1-facet_grid chart(each row of facets contains a coral type)
2-drop down menu for 5 coral types.
What I would like to do is to link the menu options to the facets. For example: if the user selects 'blue corals' my graph would only show the facets that contains this coral type.
this is my code (app.R):
library(shiny)
library(ggplot2)
mydata <- read.csv("myfile.csv")
#ui
ui<-fluidPage(
headerPanel("Coral Type Rates"),
sidebarPanel(
selectInput("CoralType", "Please Select Coral Type",
choices=c("blue corals","soft corals",
"hard Coral","sea Pens","sea Fans")),
selectInput("Smoothers","Please select smoother",
choices=c("loose","lm")
),
mainPanel(
plotOutput("myplot")
)
))
#server
server<-function(input, output){
#converting types
mydata$value <-as.numeric(sub("%", "", as.character(mydata$value)))
mydata$value<-mydata$value/100
mydata$location<-as.character((mydata$location))
#sorting by latitude
mydata<-mydata[order(mydata$latitude),]
mydatalocation<-unique(mydata$location)
mydatalocation
mydata$location<-factor((mydata$location),levels=mydatalocation)
#ggplot graph
output$myplot <- renderPlot({
ggplot(mydata,aes(mydata$year,mydata$value,colour=coralType))+
geom_point(size=2)+facet_grid(mydata$coralType~mydata$location,scales="free")+
geom_smooth(method="loess", size=1, color="black")+
geom_smooth(method="lm", size=1, color="blue")+
theme_bw()
})
}
shinyApp(ui=ui, server=server)
this is the facet_grid:
I tried using reactivevalues() and if statement, but since I'm new to R I could not make it work.
Thank you,