I'm trying to generate a dataframe that will later be used to plot a series of coordinates on a leaflet map. The idea is that the selected input from a dropdown menu creates two variables with the corresponding latitud and longitude. These variables are later inserted as columns to a dataframe and distances calculated. The distance between the selected lat lon are also added as a column to the same dataframe.
What I need is to be able to create a new dataframe by filtering the previously mentioned one. The problem that I am facing is that the first dataframe is now a function, given its reactive nature. I provide some code to ilustrate the situation:
server <- function(input, output,session) {
estacion<-reactive(input$estacion)
lonOBS <- reactive(estaciones$lon[estaciones$nombres == estacion()])
latOBS <- reactive(estaciones$lat[estaciones$nombres == estacion()])
globals<- reactiveValues(mydf=df_mapas)
observe({
globals$mydf$lonOBS <- lonOBS()
globals$mydf$latOBS <- latOBS()
globals$mydf$distOBS <- distHaversine(cbind(globals$mydf$lonOBS,
globals$mydf$latOBS),
cbind(globals$mydf$longitud,
globals$mydf$latitud))
})
data_to_map1<-globals$mydf %>% filter(distOBS <= "100" &
velocidad >= 50)
Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
What I'm looking for is to have data_to_map1
as a dataframe to then use to plot the coordinates on a map just like it works outside shiny but updated according to the input.
Thanks in advance.