I am developping an app using R shiny where a reactive plot wil be outputed based on a certain filtration .But my problem is how to replace that plot with another one that using nearpoints observent or whateverelse.Below the code of a similar app(diffrence here is that data not filtrated like in my app where i used reactive for plot since the user filter the data as much as he wants and get correspeendent plot).
data<-mpg
output$p1<-reactive({ ggplot( data, aes(x = displ, y = cty)) +
geom_point(size = 7, colour = "#EF783D", shape = 17) +
geom_line(color = "#EF783D") +
ggtitle(paste("Insights : ", na.omit(filters$manufacturer), na.omit(filters$model), na.omit(filters$displ), na.omit(filters$year), sep = ", ")))})
observeEvent(input$plot_click,
{ a<- nearPoints(data, input$plot_click, threshold = 10, maxpoints = 1,
addDist = F)$model
dt<-dt[dt$model==a,]
df<-data.frame("model"=dt$model,"displ"=dx$displ)
ggplot(df, aes(x = model,y = displ,group = 1)) +
geom_point()
})