I am developing a shiny app, in which I am uploading and reading multiple datafiles.
I want to detect the changepoint according to the cpt.meanvar. For that, I am using changepoint and changepoint.np packages.
I want to be able to extract a particular part of the plot (i.e dataset) which to be used for further analysis and processing in the shiny app. This part should be able to get detected and extracted by detecting the changepoints.
M2 <- data.frame(x,y)
Here is my attempt to detect the changepoint and plot them on the graph:
df1 <- data.frame(x = M2[,1], y = (M2[,2]-min(M2[1,2])))
mcpt <- changepoint::cpt.meanvar(df1$y, method = "PELT")
plot(mcpt)
This generates just a normal plot, when in reality it has to be a scatterplot.
Here is how the plot looks like:

Question 1) How can do the same thing with ggplotor plotly?
Question 2) If I were to separate some specific part of this scatterplot and use that part for further analysis, how can I do that? For e.g. if I want the app to automatically detect and extract the datapoints of the middle flat surface, which is raised above from the 0 line.
