Hello,
i'm working a shiny app that plot a raster layer and when you click on the plot thath makes a time series, a kernel density and other stuff. I'm trying to make that when you click the plot it also plot the coordinates points, but when this happens the plot refresh.
I'm using a function to plot an this is the server part of the script:
Extract coordinates
#defining raster click options
Coords<- reactive({
req(input$rasPlot_click$x)
c(input$rasPlot_click$x,input$rasPlot_click$y)
})
#EVI, anomalies & probabilitie selectable plot
output$rasPlot <- renderPlot({
dinput <- input$fechas
data <- switch(input$dataset,
"EVI" = "EVI",
"Anomalia" = "Anomalia",
"Probabilidad" = "Probabilidad")
color <- switch(input$dataset,
"EVI" = "EVI",
"Anomalia" = "Anomalia",
"Probabilidad" = "Probabilidad")
rango <- switch(input$dataset,
"EVI" = "EVI",
"Anomalia" = "Anomalia",
"Probabilidad" = "Probabilidad")
x <- reactive({input$rasPlot_click$x})
y <- reactive({input$rasPlot_click$y})
plot_index(data = data,color = color,range = rango,dinput = dinput,x=x(),y=y()) ###function thath make the raster plot
},height = 650,width = 650,res = 120)
plot_index function
plot_index<-function(data, color, range, dinput,x,y){
if(data == "EVI")
rast<- stack("./data/EVI.tif")
if(data == "Anomalia")
rast <- stack("./data/Anom.tif")
if(data == "Probabilidad")
rast <- stack("./data/Prob.tif")
if(data == "EVI")
paleta<- c('#f7fcfd','#e5f5f9','#ccece6','#99d8c9','#66c2a4','#41ae76','#238b45','#006d2c','#00441b')
if(data == "Anomalia")
paleta<- c('#b2182b','#d6604d','#f4a582','#fddbc7','#f7f7f7','#d1e5f0','#92c5de','#4393c3','#2166ac')
if(data == "Probabilidad")
paleta<-c ("#fff7ec","#fee8c8","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#b30000",
"#7f0000")
if(data == "EVI")
z<-c(0,1)
if(data == "Anomalia")
z<-c(-0.3,0.3)
if(data == "Probabilidad")
z<-c(0,100)
#Read dates
dates.table<-read.csv("./data/all_791_dates.csv", sep = ",", header=T)
dates <-as.Date(dates.table$date, format='%d/%m/%Y')
PNLC <- readOGR(dsn = "./data", layer = "pn_la_campana")
PNLC<-spTransform(x = PNLC,CRSobj = "+proj=utm +zone=19 +south +datum=WGS84 +units=m +no_defs")
dateSelect<-which(dates==dinput)
lat<-y
lon<-x
plot((rast[[dateSelect]]/10000), col=paleta, zlim=z)
plot(PNLC,add=T)#"+proj=utm +zone=19 +south +datum=WGS84 +units=m +no_defs"
points(lon,lat,pch=13)
#plot(OC, add=T,color=rgb(0,0,0,alpha=1), border="transparent")
}
Thanks a lot and sorry for my english grammar