My question is similar to the following two:
Make object created inside one reactive object available to another in shiny
With the important difference that the object I want to create can't be defined in a single line. Therefore my understanding after checking this example is that I should use reactive({ })
, But I'm getting the good old error "object of type 'closure' is not subsettable" and I can't figure out what am I doing wrong.
Specifically I'm trying to subset a large dataframe according to a set of variables the user would define playing with widgets. Then I would use this dataframe to perform different plots using renderPlot()
independently but with the same data.
My code looks like:
# mydf is defined previously in global.R
shinyServer(function(input, output) {
##Subset
mydf2<- reactive({
# by desired Altitude
mydf<-mydf[c(mydf$Altitud>=input$Altitud[1], mydf$Altitud<=input$Altitud[2]),]
# by desired Longitude
mydf<-mydf[c(mydf$Longitud>=input$Longitud[1], mydf$Longitud<=input$Longitud[2]),]
# by desired Latitud
mydf<-mydf[c(mydf$Latitud>=input$Latitud[1], mydf$Latitud<=input$Latitud[2]),]
mydf
})
## PCA
output$pca<- renderPlot({
plot(mydf2$eigenvect2, mydf2$eigenvect1)
})
## Other plotting
...
})
The subsetting works perfectly well if I take it out from reactive
and paste it inside output$pca<- renderPlot({
so this can't be the problem.
Help very much appreciated, this is my first shiny app.